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