#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int alf = 26;
const int dig = 10;
const int two = 2;
const int th = 3;
const long long prost = 239;
const long long btc = 30;
const double eps = 1e-8;
const long long INF = (long long)(1e18 + 239);
const int BIG = (int)(1e9 + 239);
const int MOD = 1e9 + 7;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int M = (int)(2e5 + 239);
const int N = (int)(2e3 + 239);
const int L = 19;
const int T = (1 << 18) + 239;
const int B = 500;
const int X = 5010;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<pair<int, int>> v = {make_pair(0, 0)};
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    vector<int> dl = {-1, 1};
    if (s[i] == '0')
      dl = {-1};
    else if (s[i] == '1')
      dl = {1};
    vector<pair<int, int>> nw;
    for (pair<int, int> t : v)
      for (int x : dl) {
        pair<int, int> l = t;
        l.first += x;
        l.second += x;
        l.first = min(l.first, 0);
        l.second = max(l.second, 0);
        if (!nw.empty()) {
          int was_len = nw.back().second - nw.back().first;
          int nw_len = l.second - l.first;
          if (nw_len > was_len) continue;
          if (nw_len < was_len) nw.clear();
        }
        nw.push_back(l);
      }
    sort(nw.begin(), nw.end());
    nw.resize(unique(nw.begin(), nw.end()) - nw.begin());
    v = nw;
  }
  cout << v[0].second - v[0].first << "\n";
  return 0;
}
