#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<char, ll>;
using vl = vector<ll>;
using Map = map<ll, ll>;
using Tup = tuple<ll, ll, ll>;
using vvl = vector<vector<ll>>;
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
signed main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  ll n = S.size();
  deque<P> deq;
  ll ren = 1;
  for (ll i = 1; i < n; ++i) {
    if (S[i - 1] == S[i])
      ren++;
    else {
      deq.emplace_back(P(S[i - 1], ren));
      ren = 1;
    }
  }
  deq.emplace_back(P(S[n - 1], ren));
  ll maxren = 0;
  for (auto p : deq)
    if (p.first != '?') chmax(maxren, p.second);
  if (maxren == 0) {
    cout << (1) << "\n";
    return 0;
  }
  vector<char> T(0);
  for (auto p : deq) {
    if (p.first != '?') {
      for (ll i = 0; i < p.second; ++i) T.emplace_back(p.first);
    } else {
      ll c0 = 0, c1 = 0;
      for (ll i = 0; i < p.second; ++i) {
        if ((i / maxren) % 2 == 0)
          c0++;
        else
          c1++;
      }
      vector<char> vec(p.second, '0');
      for (ll j = 1; j <= c1; ++j) {
        if (j % 2)
          vec[j] = '1';
        else
          vec[p.second - j] = '1';
      }
      for (ll j = 0; j < p.second; ++j) T.emplace_back(vec[j]);
    }
  }
  ll ans = 1;
  ll cou10 = 0;
  ll a = 0;
  for (ll i = 0; i < n; ++i) {
    if (T[i] == '1')
      cou10++;
    else
      cou10--;
    chmin(a, cou10);
    chmax(ans, cou10 - a);
  }
  vector<char> U(0);
  for (auto p : deq) {
    if (p.first != '?') {
      for (ll i = 0; i < p.second; ++i) U.emplace_back(p.first);
    } else {
      ll c0 = 0, c1 = 0;
      for (ll i = 0; i < p.second; ++i) {
        if ((i / maxren) % 2 == 0)
          c1++;
        else
          c0++;
      }
      vector<char> vec(p.second, '1');
      for (ll j = 1; j <= c0; ++j) {
        if (j % 2)
          vec[j] = '0';
        else
          vec[p.second - j] = '0';
      }
      for (ll j = 0; j < p.second; ++j) U.emplace_back(vec[j]);
    }
  }
  ll cou01 = 0;
  a = 0;
  for (ll i = 0; i < n; ++i) {
    if (U[i] == '0')
      cou01++;
    else
      cou01--;
    chmin(a, cou01);
    chmax(ans, cou01 - a);
  }
  cout << (ans) << "\n";
  return 0;
}
