#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
string s;
long long n;
bool check(long long mid) {
  vector<vector<long long>> dp1(2, vector<long long>(n + 1, -1)),
      dp2(2, vector<long long>(n + 1, -1));
  long long u = mid, v = mid;
  if (mid % 2 == 0)
    v--;
  else
    u--;
  dp1[0][0] = 0;
  dp1[1][0] = u;
  dp2[0][0] = 1;
  dp2[1][0] = v;
  for (long long i = (0); i < ((n)); ++i) {
    if (s[i] == '0') {
      if (dp1[1][i] <= 0)
        dp2[0][i + 1] = dp2[1][i + 1] = -1;
      else {
        dp2[1][i + 1] = dp1[1][i] - 1;
        dp2[0][i + 1] = max(1LL, dp1[0][i] - 1);
      }
      if (dp2[0][i] == -1)
        dp1[0][i + 1] = dp1[1][i + 1] = -1;
      else {
        dp1[1][i + 1] = dp2[1][i] - 1;
        dp1[0][i + 1] = dp2[0][i] - 1;
      }
    } else if (s[i] == '1') {
      if (dp1[1][i] == -1 || dp1[0][i] + 1 > v)
        dp2[0][i + 1] = dp2[1][i + 1] = -1;
      else {
        dp2[1][i + 1] = min(v, dp1[1][i] + 1);
        dp2[0][i + 1] = dp1[0][i] + 1;
      }
      if (dp2[0][i] == -1 || dp2[0][i] + 1 > u)
        dp1[0][i + 1] = dp1[1][i + 1] = -1;
      else {
        dp1[1][i + 1] = min(u, dp2[1][i] + 1);
        dp1[0][i + 1] = dp2[0][i] + 1;
      }
    } else {
      dp2[0][i + 1] = max(1LL, dp1[0][i] - 1);
      dp2[1][i + 1] = min(v, dp1[1][i] + 1);
      dp1[0][i + 1] = max(0LL, dp2[0][i] - 1);
      dp1[1][i + 1] = min(u, dp2[1][i] + 1);
      if (dp1[0][i] == -1) dp2[0][i + 1] = dp2[1][i + 1] = -1;
      if (dp2[0][i] == -1) dp1[0][i + 1] = dp1[1][i + 1] = -1;
    }
  }
  return dp1[0][n] != -1 || dp2[0][n] != -1;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  n = s.size();
  long long ng = 0, ok = 2e5 + 10;
  while (abs(ng - ok) > 1) {
    long long mid = ng + (ok - ng) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  cout << ok << endl;
  return 0;
}
