#include <bits/stdc++.h>
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO {
  FIO() {
    std::cin.tie(0);
    std::cout.tie(0);
    std::ios_base::sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(15);
  }
} fIO;
int main() {
  std::string s;
  std::cin >> s;
  int n = s.size();
  lnt ans = 1;
  {
    lnt diff = 0;
    lnt curr = 0;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '0')
        curr++;
      else if (s[i] == '1')
        curr--;
      else {
        if (curr > 0)
          curr--;
        else
          curr++;
      }
      diff = std::max(diff, curr);
    };
    ans = std::max(ans, diff);
  }
  for (int i = 0; i < (n); ++i) {
    if (s[i] == '1')
      s[i] = '0';
    else if (s[i] == '0')
      s[i] = '1';
  }
  {
    lnt diff = 0;
    lnt curr = 0;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '0')
        curr++;
      else if (s[i] == '1')
        curr--;
      else {
        if (curr > 0)
          curr--;
        else
          curr++;
      }
      diff = std::max(diff, curr);
    };
    ans = std::max(ans, diff);
  }
  std::cout << (ans) << '\n';
}
