#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
  }
  return os;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  pair<int, pair<int, int>> cur(0, make_pair(0, 0));
  auto L = [&]() {
    auto ret = cur;
    if (ret.second.second == 0) {
      ++ret.first;
    } else {
      --ret.second.first;
      --ret.second.second;
      if (ret.second.first < 0) ret.second.first += 1;
    }
    return ret;
  };
  auto R = [&]() {
    auto ret = cur;
    if (ret.second.first == ret.first) {
      ++ret.first;
      ++ret.second.first;
      ++ret.second.second;
    } else {
      ++ret.second.first;
      ++ret.second.second;
      if (ret.second.second > ret.first) ret.second.second -= 1;
    }
    return ret;
  };
  auto mer = [&](const pair<int, pair<int, int>>& a,
                 const pair<int, pair<int, int>>& b) {
    if (a.first < b.first) return a;
    if (a.first > b.first) return b;
    return make_pair(a.first, make_pair(min(a.second.first, b.second.first),
                                        max(a.second.second, b.second.second)));
  };
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0')
      cur = L();
    else if (s[i] == '1')
      cur = R();
    else
      cur = mer(L(), R());
  }
  cout << cur.first << '\n';
  return 0;
}
