#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char s[N];
int n, head[N], pre[N], nxt[N], e, ans, in[N], p[N];
bool vis[N], vt[N];
int tot;
priority_queue<pair<int, int> > q;
void init() {
  memset(head, -1, sizeof(head));
  e = 0;
}
void addedge(int u, int v) { pre[e] = v, nxt[e] = head[u], head[u] = e++; }
void dfs(int u, int f, int dep) {
  p[u] = f;
  if (head[u] == -1) {
    if (dep > 2) {
      ++ans;
      int c = u;
      while (c != -1) {
        vis[c] = 1;
        c = p[c];
      }
    } else
      q.push(make_pair(f, u));
  }
  for (int i = head[u]; ~i; i = nxt[i]) {
    int v = pre[i];
    dfs(v, u, dep + 1);
  }
}
bool judge(int x) {
  if (vt[(x + n - 1) % n]) return false;
  if (vt[(x + 1) % n]) return false;
  return true;
}
void deal(int x) {
  vt[x] = 1;
  vis[(x + n - 1) % n] = 1;
  vis[(x + 1) % n] = 1;
}
int main() {
  cin >> s;
  n = strlen(s);
  init();
  int i;
  for (i = 0; i < n; ++i) {
    if (s[i] == '0') {
      addedge(i, (i + 1) % n);
      ++in[(i + 1) % n];
    } else {
      addedge((i + 1) % n, i);
      ++in[i];
    }
  }
  for (i = 0; i < n; ++i)
    if (!in[i]) dfs(i, -1, 1);
  while (!q.empty()) {
    int u = q.top().first, v = q.top().second;
    q.pop();
    if (!vis[u] && judge(u)) {
      ++ans;
      deal(u);
    }
    if (!vis[v] && judge(v)) {
      ++ans;
      deal(v);
    }
    vis[u] = vis[v] = 1;
  }
  cout << ans << endl;
  return 0;
}
