#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
char s[N];
int a[N];
int main() {
  while (~scanf("%s", s + 1)) {
    int n = strlen(s + 1);
    int m = 0, cnt = 0;
    s[0] = s[1];
    s[n + 1] = 1 - (s[n] - '0') + '0';
    for (int i = 1; i <= n + 1; ++i) {
      if (s[i] == s[i - 1]) {
        ++cnt;
      } else {
        a[++m] = cnt;
        cnt = 1;
      }
    }
    if (m & 1) {
      a[1] += a[m];
      --m;
    }
    int flag = 0;
    for (int i = 1; i <= m; ++i) {
      if (a[i] >= 2) flag = 1;
    }
    int p = 1;
    if (flag) {
      while (a[p] == 1) {
        a[++m] = a[p++];
      }
    }
    int ans = 0;
    cnt = 0;
    for (int i = p; i <= m; ++i) {
      if (a[i] >= 2) {
        ans += cnt / 2 + 1;
        cnt = 0;
      } else {
        ++cnt;
      }
    }
    ans += cnt / 2;
    printf("%d\n", ans);
  }
  return 0;
}
