#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int v[1000000], a[1000000];
vector<int> d[1000000], r[1000000];
void dfs(int i) {
  v[i] = 1;
  for (int j = 0; j < d[i].size(); j++)
    if (!v[d[i][j]]) dfs(d[i][j]);
}
void rdfs(int i) {
  v[i] = 1;
  for (int j = 0; j < r[i].size(); j++)
    if (!v[r[i][j]]) rdfs(r[i][j]);
}
int main() {
  int i, n = 0, l;
  cin >> s;
  l = strlen(s);
  for (i = 0; i < l; i++) {
    if (s[i] == '0') {
      a[i]--;
      a[(i + 1) % l]++;
      d[i].push_back((i + 1) % l);
      r[(i + 1) % l].push_back(i);
    } else {
      a[i]++;
      a[(i + 1) % l]--;
      r[i].push_back((i + 1) % l);
      d[(i + 1) % l].push_back(i);
    }
  }
  for (i = 0; i < l; i++)
    if (!v[i] && !a[i]) {
      n++;
      dfs(i);
      rdfs(i);
    }
  for (i = 0; i < l; i++)
    if (!v[i]) {
      n++;
      if (a[i] < 0)
        dfs(i);
      else
        rdfs(i);
    }
  cout << n << endl;
  return 0;
}
