#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int O = 1e6 + 5;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
char s[O];
int cnt[O];
int main(void) {
  cin >> s;
  int n = strlen(s);
  int i, j = 1;
  memset(cnt, 0, sizeof(cnt));
  cnt[1] = 1;
  for (i = 1; i <= n - 1; ++i) {
    if (s[i] != s[i - 1]) j++;
    cnt[j]++;
  }
  if (s[0] == s[n - 1]) cnt[1] += cnt[j], j--;
  int ans = 0, jack = 0;
  for (i = 1; i <= j; ++i) {
    if (cnt[i] == 1)
      jack++;
    else {
      ans += jack / 2 + 1;
      jack = 0;
    }
  }
  if (cnt[j] == 1) ans += jack / 2;
  cout << ans << endl;
  return 0;
}
