#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e6 + 5;
string s;
int a[MaxN];
int cnt, n;
void Init() {
  ios::sync_with_stdio(false);
  cin >> s;
  n = s.size();
}
void Main() {
  for (int i = 0; i < n; ++i) {
    if (!i || s[i] ^ s[i - 1])
      a[++cnt] = 1;
    else
      a[cnt] = 0;
  }
  if (s[0] == s[n - 1]) a[1] = 0, --cnt;
  int temp = 0, ans = 0;
  for (int i = 1; i <= cnt; ++i) {
    if (a[i])
      ++temp;
    else
      ans += (temp >> 1) + 1, temp = 0;
  }
  ans += (temp >> 1);
  cout << ans << endl;
}
int main() {
  Init();
  Main();
  return 0;
}
