#include <bits/stdc++.h>
using namespace std;
int g1, g2, m, x, y;
vector<int> Adj[2001505];
int Dist[2001505], Par[2001505];
bool BFS() {
  queue<int> Cola;
  for (int i = 1; i <= g1; ++i)
    if (Par[i] == 0) {
      Cola.push(i);
      Dist[i] = 0;
    } else
      Dist[i] = 2001505;
  Dist[0] = 2001505;
  while (!Cola.empty()) {
    int v = Cola.front();
    Cola.pop();
    for (int i = 0; i < Adj[v].size(); i++)
      if (Dist[Par[Adj[v][i]]] == 2001505) {
        Cola.push(Par[Adj[v][i]]);
        Dist[Par[Adj[v][i]]] = Dist[v] + 1;
      }
  }
  return Dist[0] != 2001505;
}
bool DFS(int x) {
  for (int i = 0; i < Adj[x].size(); i++) {
    if (Dist[Par[Adj[x][i]]] == Dist[x] + 1 &&
        (Par[Adj[x][i]] == 0 || DFS(Par[Adj[x][i]]))) {
      Par[x] = Adj[x][i];
      Par[Adj[x][i]] = x;
      return 1;
    }
  }
  Dist[x] = 2001505;
  return 0;
}
string s;
int main() {
  cin >> s;
  g2 = g1 = s.length();
  if (s[g1 - 1] == '0') {
    Adj[g1].push_back(g1 + 1);
  } else {
    Adj[1].push_back(g1 + g1);
  }
  for (int i = 0; i < g1 - 1; i++) {
    if (s[i] == '0') {
      Adj[i + 1].push_back(g1 + i + 2);
    } else {
      Adj[i + 2].push_back(i + 1 + g1);
    }
  }
  int res = 0;
  while (BFS())
    for (int i = 1; i <= g1; i++)
      if (!Par[i] && DFS(i)) res++;
  printf("%d\n", g1 - res);
  return 0;
}
