#include <bits/stdc++.h>
using namespace std;
struct brac {
  int x, y, z;
  brac() { x = y = z = 0; }
  brac(int xx, int yy, int zz) {
    x = xx;
    y = yy;
    z = zz;
  }
  void merge(const brac& b1, const brac& b2) {
    x = b1.x + b2.x + 2 * min(b1.y, b2.z);
    y = b1.y + b2.y - min(b1.y, b2.z);
    z = b1.z + b2.z - min(b1.y, b2.z);
  }
};
string s;
int m;
brac seg[4000000 + 5];
void build(int v, int l, int r) {
  if (l == r) {
    if (s[l] == '(')
      seg[v] = brac(0, 1, 0);
    else
      seg[v] = brac(0, 0, 1);
  } else {
    build(v << 1, l, ((l + r) >> 1));
    build((v << 1) + 1, ((l + r) >> 1) + 1, r);
    seg[v].merge(seg[v << 1], seg[(v << 1) + 1]);
  }
}
int main() {
  cin >> s;
  int ss = (int)s.length();
  build(1, 0, ss - 1);
  cout << seg[1].x;
}
