#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string s; std::cin >> s;
  int da[4], db[4];
  da[1] = db[0] = da[3] = db[3] = -1;
  da[0] = db[1] = 1;
  int a0 = 0, b0 = 0, a1 = -1, b1 = -1, ma = 0, mb = 0;
  for(int i = 0; i < s.size(); ++i) {
    char c = s[i];
    ma += da[c&3]; if(ma < 0) ma = 0;
    mb += db[c&3]; if(mb < 0) mb = 0;
    if(i&1) {
      a0 = std::max(a0, ma);
      b0 = std::max(b0, mb);
    } else {
      a1 = std::max(a1, ma);
      b1 = std::max(b1, mb);
    }
  }
  ma = std::max(a0, a1); if(a0 == a1) ++ma;
  mb = std::max(b0, b1); if(b0 == b1) ++mb;
  fin(std::max(ma, mb));
  return 0;
}
