#include <bits/stdc++.h>
using namespace std;
int ans, mn = 1e9;
string s;
map<int, int> x;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int j = i;
    while (s[j] == s[i]) j++;
    x[s[i] - 'a'] += j - i + 1;
    ans++;
    i = j - 1;
  }
  for (int i = 0; i < 26; i++)
    if (x[i]) mn = min(mn, x[i]);
  cout << min(ans + (mn >= 2), (int)s.size()) << endl;
  return 0;
}
