#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 < (int)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 = 1;
  if (v[0].c != '?') ans = max(ans, v[0].cnt);
  for (int i = 1; i < (int)v.size(); i++) {
    if (i + 1 == (int)v.size() && v[i].c == '?') break;
    int temp = 0;
    if (v[i].c != '?') {
      ans = max(ans, v[i].cnt);
      for (int k = 1; v[i].cnt > temp && i + k < (int)v.size(); k++) {
        if (v[i + k].c == v[i].c) {
          if (v[i].cnt > temp) v[i + k].cnt += v[i].cnt - temp;
          break;
        }
        temp += v[i + k].cnt;
      }
    }
    if (v[i - 1].c == v[i + 1].c && v[i - 1].c != '?') {
      if (v[i].cnt % 2 == 0 && v[i].c == '?') ans = max(ans, 2);
    }
  }
  cout << ans << endl;
  return 0;
}
