#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 10;
const long long inf = 1ll << 60;
const long long mod = 1e9 + 7;
void GG() {
  cout << "0\n";
  exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
  long long re = 1;
  while (n > 0) {
    if (n & 1) re = re * a % mo;
    a = a * a % mo;
    n >>= 1;
  }
  return re;
}
long long inv(long long b, long long mo = mod) {
  if (b == 1) return b;
  return (mo - mo / b) * inv(mo % b, mo) % mo;
}
const int maxn = 1e6 + 5;
int p[2][maxn];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  string second;
  cin >> second;
  int n = second.length();
  for (int i = 0; i < n; ++i) {
    if (second[i] == '0') {
      p[0][i + 1]++;
    }
    if (second[i] == '1') {
      p[1][i + 1]++;
    }
    p[0][i + 1] += p[0][i];
    p[1][i + 1] += p[1][i];
    ;
  }
  int re = 0;
  array<int, 2> bl = {{10000000, 10000000}};
  for (int r = 0; r <= n; ++r) {
    for (int k = 0; k < 2; ++k) {
      re = max(re, 2 * (p[k][r]) - r - bl[k]);
      bl[k] = min(bl[k], 2 * p[k][r] - r);
    }
  }
  if (re == 1) {
    bool x1 = 0, x0 = 0;
    for (int i = 0; i < n; ++i) {
      if (second[i] != '?') {
        (((second[i] == '0') ^ (i & 1)) ? x1 : x0) = 1;
      }
    }
    if (x1 && x0) re++;
  }
  cout << re << '\n';
}
