#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int sum[1000005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int ans = 0, cnt = 0, t = 0;
  for (int i = 0; i < n; ++i) {
    if (!i || s[i] != s[i - 1])
      sum[cnt++] = 1;
    else
      ++sum[cnt - 1];
  }
  if (s[0] == s[n - 1]) sum[0] += sum[--cnt];
  for (int i = 0; i < cnt; ++i) {
    if (sum[i] == 1)
      ++t;
    else {
      ans += t / 2 + 1;
      t = 0;
    }
  }
  printf("%d\n", ans + t / 2);
  return 0;
}
