#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void *wmem;
char memarr[96000000];
template <class S, class T>
inline S max_L(S a, T b) {
  return a >= b ? a : b;
}
template <class T>
inline void walloc1d(T **arr, int x, void **mem = &wmem) {
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]);
  (*arr) = (T *)(*mem);
  (*mem) = ((*arr) + x);
}
template <class T1>
void sortA_L(int N, T1 a[], void *mem = wmem) {
  sort(a, a + N);
}
template <class T1, class T2>
void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem) {
  int i;
  pair<T1, T2> *arr;
  walloc1d(&arr, N, &mem);
  for (i = (0); i < (N); i++) {
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr + N);
  for (i = (0); i < (N); i++) {
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline int my_getchar_unlocked() {
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if (s == e && e == 1048576) {
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if (s == e) {
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c) {
  int i;
  for (;;) {
    i = my_getchar_unlocked();
    if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) {
      break;
    }
  }
  c = i;
}
inline int rd(char c[]) {
  int i;
  int sz = 0;
  for (;;) {
    i = my_getchar_unlocked();
    if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) {
      break;
    }
  }
  c[sz++] = i;
  for (;;) {
    i = my_getchar_unlocked();
    if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) {
      break;
    }
    c[sz++] = i;
  }
  c[sz] = '\0';
  return sz;
}
struct MY_WRITER {
  char buf[1048576];
  int s;
  int e;
  MY_WRITER() {
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER() {
    if (s) {
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
};
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a) {
  if (MY_WRITER_VAR.s == MY_WRITER_VAR.e) {
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a) { my_putchar_unlocked(a); }
inline void wt_L(int x) {
  int s = 0;
  int m = 0;
  char f[10];
  if (x < 0) {
    m = 1;
    x = -x;
  }
  while (x) {
    f[s++] = x % 10;
    x /= 10;
  }
  if (!s) {
    f[s++] = 0;
  }
  if (m) {
    my_putchar_unlocked('-');
  }
  while (s--) {
    my_putchar_unlocked(f[s] + '0');
  }
}
template <class S>
void arrErase(int k, int &sz, S a[]) {
  int i;
  sz--;
  for (i = (k); i < (sz); i++) {
    a[i] = a[i + 1];
  }
}
template <class S, class T>
void arrErase(int k, int &sz, S a[], T b[]) {
  int i;
  sz--;
  for (i = (k); i < (sz); i++) {
    a[i] = a[i + 1];
  }
  for (i = (k); i < (sz); i++) {
    b[i] = b[i + 1];
  }
}
template <class S, class T, class U>
void arrErase(int k, int &sz, S a[], T b[], U c[]) {
  int i;
  sz--;
  for (i = (k); i < (sz); i++) {
    a[i] = a[i + 1];
  }
  for (i = (k); i < (sz); i++) {
    b[i] = b[i + 1];
  }
  for (i = (k); i < (sz); i++) {
    c[i] = c[i + 1];
  }
}
int N;
char S[1000000 + 2];
int ds;
int dp0[100];
int dp1[100];
int ns;
int nx0[100];
int nx1[100];
int main() {
  wmem = memarr;
  int i;
  int j;
  int k;
  int res;
  N = rd(S);
  int Lj4PdHRW;
  int KL2GvlyY;
  int Q5VJL1cS;
  Lj4PdHRW = 0;
  KL2GvlyY = N;
  while (Lj4PdHRW < KL2GvlyY) {
    if ((Lj4PdHRW + KL2GvlyY) % 2 == 0) {
      Q5VJL1cS = (Lj4PdHRW + KL2GvlyY) / 2;
    } else {
      Q5VJL1cS = (Lj4PdHRW + KL2GvlyY - 1) / 2;
    }
    ds = 1;
    dp0[0] = dp1[0] = 0;
    for (k = (0); k < (N); k++) {
      ns = 0;
      for (i = (0); i < (ds); i++) {
        if (S[k] == '0' || S[k] == '?') {
          nx0[ns] = max_L(0, dp0[i] + 1);
          nx1[ns] = max_L(0, dp1[i] - 1);
          ns++;
        }
        if (S[k] == '1' || S[k] == '?') {
          nx0[ns] = max_L(0, dp0[i] - 1);
          nx1[ns] = max_L(0, dp1[i] + 1);
          ns++;
        }
      }
      ds = 0;
      for (i = (0); i < (ns); i++) {
        if (nx0[i] <= Q5VJL1cS && nx1[i] <= Q5VJL1cS) {
          dp0[ds] = nx0[i];
          dp1[ds] = nx1[i];
          ds++;
        }
      }
      for (;;) {
        int fg = 0;
        for (i = (0); i < (ds); i++) {
          for (j = (0); j < (ds); j++) {
            if (i != j && dp0[i] >= dp0[j] && dp1[i] >= dp1[j]) {
              arrErase(i, ds, dp0, dp1);
              fg++;
            }
          }
        }
        if (!fg) {
          break;
        }
      }
      sortA_L(ds, dp0, dp1);
      while (ds >= 4) {
        arrErase(2, ds, dp0, dp1);
      }
    }
    if (ds) {
      KL2GvlyY = Q5VJL1cS;
    } else {
      Lj4PdHRW = Q5VJL1cS + 1;
    }
  }
  res = KL2GvlyY;
  wt_L(res);
  wt_L('\n');
  return 0;
}
