#include <bits/stdc++.h>
using namespace std;
struct XORBasis {
  long long n;
  vector<unsigned long long> p;
  vector<unsigned long long> ans;
  XORBasis(long long k) : n(k) { p.resize(k + 1); }
  void rebuilt() {
    ans.clear();
    for (long long i = 0; i <= n; ++i) {
      if (p[i]) ans.push_back(p[i]);
    }
  }
  void insert(unsigned long long u) {
    for (long long i = n; i >= 0; --i) {
      if (u & (1ull << i)) {
        if (p[i])
          u ^= p[i];
        else {
          p[i] = u;
          for (long long j = i - 1; j >= 0; --j) {
            if (p[i] & (1ull << j)) p[i] ^= p[j];
          }
          for (long long j = i + 1; j <= n; ++j) {
            if (p[j] & (1ull << i)) p[j] ^= p[i];
          }
          break;
        }
      }
    }
    rebuilt();
  }
  bool check(unsigned long long u) {
    for (long long i = n; i > -1; --i) {
      if (u & (1ull << i)) u ^= p[i];
    }
    return (u == 0);
  }
  unsigned long long kth(unsigned long long t) {
    if (t >= (1ull << (long long)(ans).size())) return -1;
    unsigned long long ret = 0;
    for (long long i = 0; i < (long long)(ans).size(); ++i) {
      if (t & (1ull << i)) ret ^= ans[i];
    }
    return ret;
  }
  unsigned long long total() { return (1ull << (long long)(ans).size()); }
};
const long long maxn = 200007;
long long n, l, r;
string s;
bool ck(long long u, long long v) {
  for (long long i = u; i < n; i += 2) {
    if (s[i] == 1 - v + '0') return 0;
  }
  return 1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> s;
  n = (long long)(s).size();
  if ((ck(0, 0) && ck(1, 1)) || (ck(0, 1) && ck(1, 0))) {
    cout << 1;
    return 0;
  }
  long long res = 0;
  for (long long i = 0; i < n; ++i) {
    if (s[i] == '0') l++, r--;
    if (s[i] == '1') r++, l--;
    if (s[i] == '?') l--, r--;
    l = max(0ll, l), r = max(0ll, r);
    res = max(res, max(l, r));
  }
  cout << max(res, 2ll) << endl;
  return 0;
}
