#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

bool f(string& s, string& t, int& i, int j) {
	int n = s.length(), m = t.length();
	for (int j = 0; j < m; j++) {
		if (i == n) return false;
		if (s[i] == '(' && t[j] == ')') {
			i--;
			if (!f(s, t, i, 0)) return false;
		}
		else if (s[i] == ')' && t[j] == '(') return false;
		else i++;
	}
	return true;
}

bool check(string& s, string& t) {
	int i = 0;
	return f(s, t, i, 0);
}

int main() {
	string s; cin >> s;
	int n = s.length(), N = n / 4;
	int m, x = 0, ma = -1;
	for (int i = 0; i < n; i++) {
		if (x > ma) {
			m = i;
			ma = x;
		}
		if (s[i] == '(') x++;
		if (s[i] == ')') x--;
	}
	vector<int> l;
	x = 0; ma = 1;
	for (int i = m - 1; i >= 0; i--) {
		if (s[i] == '(') x++;
		if (s[i] == ')') x--;
		if (x > ma) {
			l.push_back(i);
			ma = x;
		}
	}
	vector<int> r;
	x = 0; ma = 1;
	for (int i = m + 1; i <= n; i++) {
		if (s[i - 1] == ')') x++;
		if (s[i - 1] == '(') x--;
		if (x > ma) {
			r.push_back(i);
			ma = x;
		}
	}
	map<int, string> mp;
	for (int k = 0; k < l.size(); k++) {
		string t = s.substr(l[k], r[k] - l[k]);
		int m = t.length(), M = m / 4;
		if (N % M == 0) mp[M] = t;
	}
	vector<int> dp(N + 1, INT_MAX / 2);
	dp[1] = 0;
	for (auto z: mp) {
		int M = z.first;
		string t = z.second;
		for (int d = 1; d < M; d++)
			if (M % d == 0 && mp.count(d) && check(t, mp[d]))
				dp[M] = min(dp[M], dp[d] + M / d - 1);
	}
	cout << dp[N] << endl;
}