#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int stack[20];
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stack[++top] = x % 10, x /= 10;
  while (top) putchar(stack[top--] + '0');
}
template <typename T>
inline void pr1(T x) {
  write(x);
  putchar(' ');
}
template <typename T>
inline void pr2(T x) {
  write(x);
  putchar('\n');
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = x < y ? x : y;
}
template <typename T>
inline void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
const int MAXN = 1000005;
struct node {
  int L, R, pos;
  node() {}
  node(int _L, int _R, int _pos) {
    L = _L;
    R = _R;
    pos = _pos;
  }
};
char ch[MAXN];
node now;
node move2(node u) {
  if (u.L - 1 >= 1) return node(u.L - 1, u.R - 1, u.pos);
  if (u.R - 1 >= 1)
    return node(1, u.R - 1, u.pos);
  else
    return node(1, 1, u.pos + 1);
}
node move3(node u) {
  if (u.R + 1 <= u.pos + 1) return node(u.L + 1, u.R + 1, u.pos);
  if (u.L + 1 <= u.pos + 1)
    return node(u.L + 1, u.pos + 1, u.pos);
  else
    return node(u.pos + 2, u.pos + 2, u.pos + 1);
}
node move1() {
  node u = move2(now), v = move3(now);
  if (u.pos == v.pos)
    return node(min(u.L, v.L), max(u.R, v.R), u.pos);
  else if (u.pos < v.pos)
    return u;
  else
    return v;
}
int main() {
  scanf("%s", ch + 1);
  int len = strlen(ch + 1);
  reverse(ch + 1, ch + 1 + len);
  now = node(1, 1, 0);
  for (int i = 1; i <= len; i++) {
    if (ch[i] == '?')
      now = move1();
    else if (ch[i] == '1')
      now = move2(now);
    else
      now = move3(now);
  }
  pr2(now.pos);
  return 0;
}
