#include <iostream>
#include <stack>
using namespace std;
int main()
{
//freopen("kuohao.in","r",stdin);
//freopen("kuohao.out","w",stdin);
string s;
cin >> s;
stack<char>st;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '(') st.push(s[i]);
else
{
if(st.size() && st.top() == '(') st.pop();
else st.push(')');
}
}
int l = 0;
int r = 0;
while (st.size())
{
if (st.top() == '(') l++;
else r++;
st.pop();
}
cout << l/2+r/2;
//fclose(stdin);
//fclose(stdout);
return 0;
}