#include <bits/stdc++.h>
using namespace std;
int read();
long long readll();
int n;
char ch[1000009];
bool check(int B) {
  int i, x = 0, y = B, z = 2;
  for (i = 1; i <= n; i++)
    if (ch[i] == '0') {
      x--;
      y--;
      if (z < 2) z ^= 1;
      if (x < 0) x = 0;
      if (x == 0 && z == 1) x = 1;
      if (x > y) return 0;
    } else if (ch[i] == '1') {
      x++;
      y++;
      if (z < 2) z ^= 1;
      if (y > B) y = B;
      if (y == B && (y & 1) != z) y--;
      if (x > y) return 0;
    } else {
      if (z == 2) {
        if (x == y) z = y & 1 ^ 1;
        x--;
        y++;
        if (x < 0) x = 0;
        if ((x & 1) != z) x++;
        if (y > B) y = B;
        if ((y & 1) != z) y--;
        if (x > y) return 0;
      } else {
        x--;
        y++;
        z ^= 1;
        if (x < 0) x = 0;
        if ((x & 1) != z) x++;
        if (y > B) y = B;
        if ((y & 1) != z) y--;
        if (x > y) return 0;
      }
    }
  return 1;
}
int main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  int l = 1, r = n, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
int read() {
  int x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
long long readll() {
  long long x = 0;
  char ch = getchar();
  bool flag = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag ? -x : x;
}
