#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  vector<pair<int, int>> ret;
  ret.emplace_back(0, 0);
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '1') {
      vector<pair<int, int>> r2;
      for (auto &r : ret) {
        auto p1 = r;
        p1.first--;
        p1.second--;
        p1.first = max(0, p1.first);
        r2.push_back(p1);
      }
      sort(r2.begin(), r2.end());
      vector<pair<int, int>> r3;
      for (int j = (int)r2.size() - 1; j >= 0; --j) {
        if (j == (int)r2.size() - 1 || r2[j].first != r2[j + 1].first) {
          r3.emplace_back(r2[j].second, r2[j].first);
        }
      }
      ret.clear();
      sort(r3.begin(), r3.end());
      for (int j = 0; j < (int)r3.size(); ++j) {
        if (j == 0 || r3[j].first != r3[j - 1].first) {
          ret.emplace_back(r3[j].second, r3[j].first);
        }
      }
    } else if (s[i] == '0') {
      vector<pair<int, int>> r2;
      for (auto &r : ret) {
        auto p2 = r;
        p2.first++;
        p2.second++;
        p2.second = min(0, p2.second);
        r2.push_back(p2);
      }
      sort(r2.begin(), r2.end());
      vector<pair<int, int>> r3;
      for (int j = (int)r2.size() - 1; j >= 0; --j) {
        if (j == (int)r2.size() - 1 || r2[j].first != r2[j + 1].first) {
          r3.emplace_back(r2[j].second, r2[j].first);
        }
      }
      ret.clear();
      sort(r3.begin(), r3.end());
      for (int j = 0; j < (int)r3.size(); ++j) {
        if (j == 0 || r3[j].first != r3[j - 1].first) {
          ret.emplace_back(r3[j].second, r3[j].first);
        }
      }
    } else if (s[i] == '?') {
      vector<pair<int, int>> r2;
      for (auto &r : ret) {
        auto p1 = r;
        p1.first--;
        p1.second--;
        p1.first = max(0, p1.first);
        auto p2 = r;
        p2.first++;
        p2.second++;
        p2.second = min(0, p2.second);
        r2.push_back(p1);
        r2.push_back(p2);
      }
      sort(r2.begin(), r2.end());
      vector<pair<int, int>> r3;
      for (int j = (int)r2.size() - 1; j >= 0; --j) {
        if (j == (int)r2.size() - 1 || r2[j].first != r2[j + 1].first) {
          r3.emplace_back(r2[j].second, r2[j].first);
        }
      }
      ret.clear();
      sort(r3.begin(), r3.end());
      for (int j = 0; j < (int)r3.size(); ++j) {
        if (j == 0 || r3[j].first != r3[j - 1].first) {
          ret.emplace_back(r3[j].second, r3[j].first);
        }
      }
    }
  }
  lint res = inf;
  for (auto &r : ret) {
    res = min(res, lint(r.first - r.second));
  }
  cout << res << "\n";
  return 0;
}
