#include <bits/stdc++.h>
using namespace std;
char d[1000005];
int N, cCoun, st, pN, fOnes, lChain, ans;
bool fChain, canUse;
int main() {
  scanf("%s", d);
  N = strlen(d);
  for (int i = 0; i < N; d[i] -= '0', i++)
    ;
  if (d[N - 1] == d[0]) {
    for (st = N - 2; d[st] == d[st + 1]; st--)
      ;
    st += 2;
    st %= N;
  } else {
    st = 1;
  }
  cCoun = 1;
  canUse = true;
  fChain = true;
  fprintf(stderr, "%d\n", st);
  for (int i = 0; i < N; st++, i++, cCoun++) {
    if (st == N || st == 0) {
      st = 0;
      pN = N - 1;
    } else {
      pN = st - 1;
    }
    if (d[st] != d[pN] || i == N - 1) {
      if (fChain) {
        fOnes += (cCoun == 1);
        fChain = (cCoun == 1);
      }
      if (cCoun == 1) {
        lChain++;
      } else {
        lChain = 0;
      }
      if (!canUse)
        canUse = true;
      else {
        ans++;
        if (cCoun == 1) canUse = false;
      }
      cCoun = 0;
    }
    fprintf(stderr, "%d: %d %d\n", i, ans, cCoun);
  }
  if (fChain) lChain = 0;
  if ((lChain + fOnes) % 2 && !canUse) ans--;
  printf("%d\n", ans);
  return 0;
}
