#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5;
int dp[2][maxn][2];
bool cv(string s)
{
	int n = s.size();
	for (int i = 0; i < s.size() - 1; i++) {
		for (int j = i + 1; j < s.size(); j++) {
			if (s[i] == s[j]) {
				for (int k = i + 1; k < j; k++) {
					if (s[k] != s[i])
						return false;
				}
			}
		}
	}
	return true;
}
int r(string s, string t)
{
	string ss, tt;
	for (int i = s.size(); i < 10; i++)ss = "0" + ss;
	for (int i = t.size(); i < 10; i++)tt = "0" + tt;
	s = ss + s;
	t = tt + t;
	int ans = 0;
	for (int i = 0; i <= 10; i++) {
		if (s[i] != t[i])ans++;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	if (n <= 7) {
		int ans = 1e5 + 6;
		for (int i = 0; i <= pow(10, n) - 1; i++) {
			string t = to_string(i);
			if (cv(t)) {
				ans = min(ans, r(s, t));
			}
		}
		cout << ans;
		return 0;
	}
	for (int i = 0; i + 1 < n; i++) {
		if (s[i] == s[i + 1])dp[1][i][0] = 0, dp[1][i][1] = 1;
		else dp[1][i][0] = 0, dp[1][i][1] = 0;
	}
	for (int i = 2; i < n; i++) {
		int j = i & 1;
		for (int p = 0, q = i + p; q < n; p++, q++) {
			if (s[p] != s[q]) {
				dp[j][p][0] = max(dp[1 - j][p][0], dp[1 - j][p + 1][0]);
				dp[j][p][1] = 0;
			}
			else if (dp[1 - j][p][1] || dp[1 - j][p + 1][1] && s[p] == s[p+1]) {
				dp[j][p][0] = 0;
				dp[j][p][1] = 1;
			}
			else if (dp[1 - j][p][1] || dp[1 - j][p + 1][1]) {
				dp[j][p][0] = 1;
				dp[j][p][1] = 0;
			}
			else if (s[p] == s[q - 1] || s[p + 1] == s[q]) {
				dp[j][p][0] = max(dp[1 - j][p][0], dp[1 - j][p + 1][0]);
				dp[j][p][1] = 0;
			}
			else {
				dp[j][p][0] = max(dp[1 - j][p][0], dp[1 - j][p + 1][0]) + 1;
				dp[j][p][1] = 0;
			}
		}
	}
	cout << dp[(n - 1) & 1][0][0];
	return 0;
}