#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
          dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b ? (a = b, true) : false;
}
template <typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b ? (a = b, true) : false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;
template <typename T = char, typename U = string>
vector<pair<T, int>> rle(const U &s) {
  int n = s.size();
  vector<pair<T, int>> res;
  T now = s[0];
  int cnt = 1;
  for (int i = (1); i < (n); ++i) {
    if (s[i] != now) {
      res.emplace_back(now, cnt);
      cnt = 0;
    }
    now = s[i];
    ++cnt;
  }
  res.emplace_back(now, cnt);
  return res;
}
int main() {
  string s;
  cin >> s;
  vector<pair<char, int>> r = rle<>(s);
  int ans = 1;
  {
    int cur = 0;
    for (auto [c, cnt] : r) {
      if (c == '0') {
        cur += cnt;
      } else {
        cur -= cnt;
      }
      chmax(ans, cur);
      chmax(cur, 0);
    }
  }
  {
    int cur = 0;
    for (auto [c, cnt] : r) {
      if (c == '1') {
        cur += cnt;
      } else {
        cur -= cnt;
      }
      chmax(ans, cur);
      chmax(cur, 0);
    }
  }
  reverse((s).begin(), (s).end());
  r = rle<>(s);
  {
    int cur = 0;
    for (auto [c, cnt] : r) {
      if (c == '0') {
        cur += cnt;
      } else {
        cur -= cnt;
      }
      chmax(ans, cur);
      chmax(cur, 0);
    }
  }
  {
    int cur = 0;
    for (auto [c, cnt] : r) {
      if (c == '1') {
        cur += cnt;
      } else {
        cur -= cnt;
      }
      chmax(ans, cur);
      chmax(cur, 0);
    }
  }
  for (int i = 0; i + 2 < r.size(); ++i) {
    if (r[i + 1].first == '?') {
      if (r[i].first == r[i + 2].first) {
        if (r[i + 1].second % 2 == 0) chmax(ans, 2);
      } else {
        if (r[i + 1].second & 1) chmax(ans, 2);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
