#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
long long rnd() {
  unsigned long long ans = 0;
  for (int i = (int)(0); i <= (int)(4); i++) ans = ans << 15 ^ rand();
  return ans % ((unsigned long long)1 << 63);
}
const int N = 1000005;
char ch[N];
int ans;
int main() {
  scanf("%s", ch + 1);
  int n = strlen(ch + 1);
  int x = 0, y = 0;
  for (int i = (int)(n); i >= (int)(1); i--) {
    if (ch[i] == '0') {
      x++;
      y--;
    } else if (ch[i] == '1') {
      x--;
      y++;
    } else {
      x--;
      y--;
    }
    x = max(x, 0);
    y = max(y, 0);
    ans = max(ans, max(x, y));
  }
  int mx = 0, l = 0, r = 0, sum = 0, zt = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    if (l == r) zt = 0;
    if (ch[i] == '0') {
      l++;
      r++;
      if (l > sum) {
        l = r = ++sum;
        if (mx & 1) l--;
        mx = 0;
        zt = l != r;
      } else if (r > sum) {
        if (zt)
          r = sum;
        else {
          r = sum - 1;
          mx |= 2;
        }
      }
    } else if (ch[i] == '1') {
      l--;
      r--;
      if (r < 0) {
        sum++;
        l = r = 0;
        if (mx & 2) r++;
        mx = 0;
        zt = l != r;
      } else if (l < 0) {
        if (zt)
          l = 0;
        else {
          l = 1;
          mx |= 1;
        }
      }
    } else {
      if (i == 1) {
        l = 0;
        r = 1;
        sum = 1;
        zt = 1;
        continue;
      }
      l--;
      r++;
      if (r > sum) {
        if (zt)
          r = sum;
        else {
          r = sum - 1;
          mx |= 2;
        }
      }
      if (l < 0) {
        if (zt)
          l = 0;
        else {
          l = 1;
          mx |= 1;
        }
      }
    }
  }
  cout << sum << endl;
}
