#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;
  }
};
vector<node> vec, las, one;
char ch[MAXN];
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);
}
pair<node, node> move1(node z) {
  node u = move2(z), v = move3(z);
  if (u.pos == v.pos)
    return make_pair(node(min(u.L, v.L), max(u.R, v.R), u.pos),
                     node(-1, -1, -1));
  else if (z.R - z.L >= 1) {
    if (u.pos < v.pos)
      return make_pair(u, node(-1, -1, -1));
    else
      return make_pair(v, node(-1, -1, -1));
  } else
    return make_pair(u, v);
}
void trans1() {
  las.clear();
  for (auto p : vec) las.emplace_back(move2(p));
  vec = las;
}
void trans0() {
  las.clear();
  for (auto p : vec) las.emplace_back(move3(p));
  vec = las;
}
bool cmp(node n1, node n2) {
  if (n1.L != n2.L) return n1.pos < n2.pos;
  return n1.pos < n2.pos;
}
void trans2() {
  las.clear();
  one.clear();
  for (auto p : vec) {
    pair<node, node> T = move1(p);
    if (T.second.L == -1) {
      node z = T.first;
      if (z.R - z.L >= 1)
        las.emplace_back(z);
      else
        one.emplace_back(z);
    } else
      one.emplace_back(T.first), one.emplace_back(T.second);
  }
  sort(one.begin(), one.end(), cmp);
  int lasx = 0;
  for (auto p : one) {
    if (p.L != lasx) las.emplace_back(p);
    lasx = p.L;
  }
  vec = las;
}
int main() {
  scanf("%s", ch + 1);
  int len = strlen(ch + 1);
  reverse(ch + 1, ch + 1 + len);
  vec.emplace_back(node(1, 1, 0));
  for (int i = 1; i <= len; i++) {
    if (ch[i] == '1')
      trans1();
    else if (ch[i] == '0')
      trans0();
    else
      trans2();
  }
  int ans = 1e9;
  for (auto p : vec) chkmin(ans, p.pos);
  pr2(ans);
  return 0;
}
