#include <bits/stdc++.h>
using namespace std;
struct atsu {
  int cnt;
  char c;
};
int main() {
  string s;
  cin >> s;
  vector<atsu> v;
  int cnt = 0;
  char pre = ' ';
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == pre)
      cnt++;
    else {
      v.push_back((atsu){cnt, pre});
      cnt = 1;
      pre = s[i];
    }
  }
  v.push_back((atsu){cnt, pre});
  int ans;
  if (v[0].c != '?') ans = v[0].cnt;
  for (int i = 1; i < (int)v.size(); i++) {
    if (i + 1 == (int)v.size() && v[i].c == '?') break;
    if (v[i].c != '?') ans = max(ans, v[i].cnt);
    if (v[i - 1].c == v[i + 1].c && v[i - 1].c != '?') {
      if (v[i].cnt < v[i - 1].cnt && v[i].cnt < v[i + 1].cnt)
        v[i + 1].cnt += v[i - 1].cnt - v[i].cnt;
      if (v[i].cnt % 2 == 0) ans = max(ans, 2);
    }
  }
  cout << ans << endl;
  return 0;
}
