#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 = 2;
  {
    bool all = true;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '?' || s[i] % 2 == i % 2) continue;
      all = false;
    }
    if (all) ans = 1;
  }
  {
    bool all = true;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '?' || s[i] % 2 != i % 2) continue;
      all = false;
    }
    if (all) ans = 1;
  }
  {
    lnt diff = 0;
    lnt min = 0;
    lnt curr = 0;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '0')
        curr++;
      else
        curr--;
      min = std::min(min, curr);
      diff = std::max(diff, curr - min);
    };
    ans = std::max(ans, diff);
  }
  {
    lnt diff = 0;
    lnt max = 0;
    lnt curr = 0;
    for (int i = 0; i < (n); ++i) {
      if (s[i] == '1')
        curr--;
      else
        curr++;
      max = std::max(max, curr);
      diff = std::max(diff, max - curr);
    };
    ans = std::max(ans, diff);
  }
  std::cout << (ans) << '\n';
}
