#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,j,k) for (int i=j;i<=k;i++)
#define dep(i,j,k) for (int i=j;i>=k;i--)
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
char s[100005];
int cntl,cntr,ans;
int main(){
// freopen("bracket.in","r",stdin);
// freopen("bracket.out","w",stdout);
scanf("%s",s+1);
rep(i,1,strlen(s+1)){
if (s[i] == '(') cntl++;
else if (s[i]==')' && cntl) cntl--;
else cntr++;
}
ans=cntl/2+(cntl%2)+cntr/2+(cntr%2);
printf("%d\n",ans);
return 0;
}