#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int record = 1e9;
unordered_map<unsigned long long, int> ua(1e7);
unordered_map<unsigned long long, int> ub(1e7);
void go(int i, int a, int b) {
  int cand = a + b;
  if (cand >= record) return;
  if (i == n + 1) {
    record = cand;
    return;
  }
  unsigned long long ha = (((unsigned long long)i) << 32) + a;
  auto ita = ua.find(ha);
  if (ita != ua.end()) {
    int ob = ita->second;
    if (ob <= b) return;
  }
  unsigned long long hb = (((unsigned long long)i) << 32) + b;
  auto itb = ub.find(hb);
  if (itb != ub.end()) {
    int oa = itb->second;
    if (oa <= a) return;
  }
  ua[ha] = b;
  ub[hb] = a;
  char c = s[i];
  if (c == '0') {
    if (a == 0) {
      go(i + 1, 0, b + 1);
    } else {
      go(i + 1, a - 1, b + 1);
    }
  } else if (c == '1') {
    if (b == 0) {
      go(i + 1, a + 1, 0);
    } else {
      go(i + 1, a + 1, b - 1);
    }
  } else {
    if ((i + a + b) & 1) {
      if (a == 0) {
        go(i + 1, 0, b + 1);
      } else {
        go(i + 1, a - 1, b + 1);
      }
      if (b == 0) {
        go(i + 1, a + 1, 0);
      } else {
        go(i + 1, a + 1, b - 1);
      }
    } else {
      if (b == 0) {
        go(i + 1, a + 1, 0);
      } else {
        go(i + 1, a + 1, b - 1);
      }
      if (a == 0) {
        go(i + 1, 0, b + 1);
      } else {
        go(i + 1, a - 1, b + 1);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  cin.tie(0);
  cin >> s;
  n = s.length();
  go(0, 0, 0);
  cout << record << endl;
  return 0;
}
