#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr double EPS = 1e-9;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  N = s.size();
  vector<int> dp(N + 21, MOD);
  set<int> odd;
  set<int> even;
  even.insert(0);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    unordered_map<int, int> ndp;
    if (s[i] != '0') {
      for (auto j : odd) {
        if (ndp.find(j + 1) == ndp.end()) ndp[j + 1] = MOD;
        ndp[j + 1] = min(ndp[j + 1], dp[j] + (j == dp[j]));
      }
      for (auto j : even) {
        if (ndp.find(j + 1) == ndp.end()) ndp[j + 1] = MOD;
        ndp[j + 1] = min(ndp[j + 1], dp[j] + (j == dp[j]));
      }
    }
    if (s[i] != '1') {
      for (auto j : odd) {
        if (ndp.find(j - 1) == ndp.end()) ndp[j - 1] = MOD;
        ndp[j - 1] = min(ndp[j - 1], dp[j]);
      }
      for (auto j : even) {
        if (j) {
          if (ndp.find(j - 1) == ndp.end()) ndp[j - 1] = MOD;
          ndp[j - 1] = min(ndp[j - 1], dp[j]);
        } else {
          if (ndp.find(0) == ndp.end()) ndp[0] = MOD;
          ndp[0] = min(ndp[0], dp[0] + 1);
        }
      }
    }
    int oddfst = MOD, evenfst = MOD;
    int oddeq = 0, eveneq = 0;
    for (auto j : ndp) {
      dp[j.first] = j.second;
      if (j.first & 1) {
        oddfst = min(oddfst, j.first);
        oddeq = max(oddeq, j.first);
      } else {
        evenfst = min(evenfst, j.first);
        eveneq = max(eveneq, j.first);
      }
    }
    odd.clear();
    even.clear();
    if (oddeq != MOD) {
      for (int j = -0; j <= 0; j += 2) {
        if (oddeq + j >= oddfst) odd.insert(oddeq + j);
      }
    }
    if (oddfst != MOD) {
      odd.insert(oddfst);
      for (int j = 0; j <= 0; j += 2) {
        odd.insert(oddfst + j);
      }
      int box = dp[oddfst];
      if (box % 2 == 0) box++;
      if (box <= oddeq) {
        dp[box] = box;
        odd.insert(box);
      }
    }
    if (eveneq != MOD) {
      for (int j = -0; j <= 0; j += 2) {
        if (eveneq + j >= evenfst) even.insert(eveneq + j);
      }
    }
    if (evenfst != MOD) {
      even.insert(evenfst);
      for (int j = 0; j <= 0; j += 2) {
        even.insert(evenfst + j);
      }
      int box = dp[evenfst];
      if (box % 2 == 1) box++;
      if (box <= eveneq) {
        dp[box] = box;
        even.insert(box);
      }
    }
  }
  int ans = MOD;
  for (auto i : odd) ans = min(ans, dp[i]);
  for (auto i : even) ans = min(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
