#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
string s;
int a[N], b[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0')
      a[i + 1] = 1;
    else if (s[i] == '1')
      b[i + 1] = 1;
  }
  for (int i = 1; i <= s.length(); i++) a[i] += a[i - 1], b[i] += b[i - 1];
  int mna = INT_MAX, mnb = INT_MAX, ans = 1;
  if (s.length() > 2) ans = 2;
  for (int i = 1; i <= s.length(); i++) {
    ans = max(ans, 2 * a[i] - i - mna);
    ans = max(ans, 2 * b[i] - i - mnb);
    mna = min(mna, 2 * a[i] - i);
    mnb = min(mnb, 2 * b[i] - i);
  }
  cout << ans;
}
