#include <bits/stdc++.h>
using namespace std;
inline int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
void remin(int& x, int y) { x = min(x, y); }
void remax(int& x, int y) { x = max(x, y); }
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<deque<int>> a(1);
  a[0].push_back(0);
  for (char c : s) {
    if (c == '0') {
      for (int i = (int)a.size() - 1; i >= 0; --i) {
        if (a[i].empty()) {
          continue;
        }
        if (a[i].front() == 0) {
          if (i + 1 >= (int)a.size()) {
            a.emplace_back();
          }
          if (a[i + 1].empty() || a[i + 1].front() > 0) {
            a[i + 1].push_front(0);
          }
          a[i].pop_front();
        }
        for (auto& x : a[i]) {
          x -= 1;
        }
      }
    } else if (c == '1') {
      for (int i = (int)a.size() - 1; i >= 0; --i) {
        if (a[i].empty()) {
          continue;
        }
        if (a[i].back() == i) {
          if (i + 1 >= (int)a.size()) {
            a.emplace_back();
          }
          if (a[i + 1].empty() || a[i + 1].back() < i + 1) {
            a[i + 1].push_back(i + 1);
          }
          a[i].pop_back();
        }
        for (auto& x : a[i]) {
          x += 1;
        }
      }
    } else {
      for (int i = (int)a.size() - 1; i >= 0; --i) {
        if (a[i].empty()) {
          continue;
        }
        deque<int> res;
        int l = 0, r = 0;
        while (l < (int)a[i].size() && r < (int)a[i].size()) {
          if (a[i][l] - 1 < a[i][r] + 1) {
            res.push_back(a[i][l++] - 1);
          } else if (a[i][l] - 1 > a[i][r] + 1) {
            res.push_back(a[i][r++] + 1);
          } else {
            res.push_back(a[i][l] - 1);
            ++l, ++r;
          }
        }
        while (l < (int)a[i].size()) {
          res.push_back(a[i][l++] - 1);
        }
        while (r < (int)a[i].size()) {
          res.push_back(a[i][r++] + 1);
        }
        if (res.front() == -1) {
          res.pop_front();
          if (i + 1 >= (int)a.size()) {
            a.emplace_back();
          }
          if (a[i + 1].empty() || a[i + 1].front() > 0) {
            a[i + 1].push_front(0);
          }
        }
        if (res.back() == i + 1) {
          res.pop_back();
          if (i + 1 >= (int)a.size()) {
            a.emplace_back();
          }
          if (a[i + 1].empty() || a[i + 1].back() < i + 1) {
            a[i + 1].push_back(i + 1);
          }
        }
        a[i].swap(res);
      }
    }
  }
  int i = 0;
  while (a[i].empty()) {
    ++i;
  }
  cout << i << "\n";
  return 0;
}
