#include <bits/stdc++.h>
using namespace std;
int solve(string s) {
  int cs = 0, mi = 0, ans = 0;
  set<int> S;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1')
      cs++;
    else
      cs--;
    mi = min(mi, cs);
    if (ans < cs - mi) {
      S.clear();
      ans = cs - mi;
    }
    if (ans == cs - mi) {
      S.insert(i % 2);
    }
  }
  if (S.size() == 2) ans++;
  return ans;
}
int main() {
  string s;
  cin >> s;
  int a = solve(s);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      s[i] = '1';
    else if (s[i] == '1')
      s[i] = '0';
  }
  int b = solve(s);
  cout << max(a, b) << endl;
}
