import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] str = br.readLine().toCharArray();
int[] dp = new int[str.length];
int maxLen = 0;
for(int i = 1; i < str.length; i++){
if(str[i] == ')'){
int prev = i - dp[i - 1] - 1;
if(prev >= 0 && str[prev] == '(')
dp[i] = dp[i - 1] + 2 + (prev > 0? dp[prev - 1]: 0);
}
maxLen = Math.max(maxLen, dp[i]);
}
System.out.println(maxLen);
}
} import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Main{
public static int MaxLength(String str){
if(str==null||str.equals("")){
return 0;
}
char[] chas=str.toCharArray();
int[] dp=new int[chas.length];
int pre=0;
int res=0;
for(int i=1;i<chas.length;i++){
if(chas[i]==')'){
pre=i-dp[i-1]-1;
if(pre>=0&&chas[pre]=='('){
dp[i]=dp[i-1]+2+(pre>0?dp[pre-1]:0);
}
}
res=Math.max(res,dp[i]);
}
return res;
}
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
System.out.print(MaxLength(str));
}
}