#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 ma = 0, mb = 0;
  int a[2] = {-1, 0}, b[2] = {-1, 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;
    a[i&1] = std::max(a[i&1], ma);
    b[i&1] = std::max(b[i&1], mb);
  }
  ma = std::max(a[0], a[1]); if(a[0] == a[1]) ++ma;
  mb = std::max(b[0], b[1]); if(b[0] == b[1]) ++mb;
  fin(std::max(ma, mb));
  return 0;
}
