#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int typ[maxn];
int dsu[maxn];
void unionS(int x, int y) {
  dsu[x] += dsu[y];
  dsu[y] = x;
}
int findS(int x) {
  if (dsu[x] < 0) return x;
  return (dsu[x] = findS(dsu[x]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  ;
  string s;
  cin >> s;
  int n = s.size();
  fill(typ, typ + maxn, 0);
  fill(dsu, dsu + maxn, -1);
  for (int i = 0; i < n; i++) {
    int j = (i + 1) % n;
    if (s[i] == '0') {
      typ[j]++;
      typ[i]--;
    } else {
      typ[i]++;
      typ[j]--;
    }
  }
  for (int i = 0; i < n; i++) {
    int j = (i + 1) % n;
    if (typ[i] == 0) continue;
    if (typ[i] != 0 && typ[j] != 0) {
      int pi = findS(i), pj = findS(j);
      if (pi == pj) continue;
      unionS(pi, pj);
    }
  }
  int ans = 0;
  for (int z = 0; z < n; z++) {
    if (dsu[z] >= 0 || typ[z] == 0) continue;
    ans += (-dsu[z] + 1) / 2;
  }
  cout << ans << endl;
}
