#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};
int n, A[1000001], B[1000001], dist[1000001];
char s[1000001];
bool used[1000001];
vector<int> v[1000001];
void bfs() {
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      dist[i] = 0;
      q.push(i);
    } else
      dist[i] = 987654321;
  }
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (int b : v[a]) {
      if (B[b] != -1 && dist[B[b]] == 987654321) {
        dist[B[b]] = dist[a] + 1;
        q.push(B[b]);
      }
    }
  }
}
bool dfs(int a) {
  for (int b : v[a]) {
    if (B[b] == -1 || dist[B[b]] == dist[a] + 1 && dfs(B[b])) {
      used[a] = true;
      A[a] = b;
      B[b] = a;
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {
    if (s[i] == '0')
      v[i].push_back((i + 1) % n);
    else
      v[(i + 1) % n].push_back(i);
  }
  int match = 0;
  memset(A, -1, sizeof(A));
  ;
  memset(B, -1, sizeof(B));
  ;
  while (1) {
    bfs();
    int flow = 0;
    for (int i = 0; i < n; i++)
      if (!used[i] && dfs(i)) flow++;
    if (flow == 0) break;
    match += flow;
  }
  printf("%d\n", n - match);
}
