#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n;
char s[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  bool good = 1;
  for (int i = 1, j = 0; i <= n; ++i, j ^= 1) {
    if (s[i] == '?' or s[i] - '0' == j) continue;
    good = 0;
    break;
  }
  if (good) {
    cout << "1\n";
    return 0;
  }
  good = 1;
  for (int i = 1, j = 1; i <= n; ++i, j ^= 1) {
    if (s[i] == '?' or s[i] - '0' == j) continue;
    good = 0;
    break;
  }
  if (good) {
    cout << "1\n";
    return 0;
  }
  int cur = 2;
  for (int i = 1; i <= n;) {
    int j = i, len = 0;
    while (j <= n and s[j] == s[i]) ++j, ++len;
    if (s[i] != '?') cur = max(cur, len);
    i = j;
  }
  bool ext = 0;
  for (int i = 1; i <= n;) {
    int j = i, len = 0;
    while (j <= n and s[j] == s[i]) ++j, ++len;
    if (s[i] == '?' and len == 1) {
      int lt = i - 1;
      while (lt > 0 and s[lt] == s[i - 1]) --lt;
      int rt = i + 1;
      while (rt <= n and s[rt] == s[i + 1]) ++rt;
      int one = i - 1 - lt, two = rt - i - 1;
      if (one == cur and two == cur and s[i - 1] != s[i + 1]) {
        ext = 1;
      }
    }
    i = j;
  }
  cout << cur + ext << '\n';
  return 0;
}
