#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string S;
    cin >> S;
    long long open = 0, ans = 0;
    for (char c : S) {
        if (c == '(') {
            open++;
        } else if (c == ')') {
            if (open > 0) {
                open--;
                ans += 2;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
