#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr double EPS = 1e-9;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  N = s.size();
  vector<int> dp(N + 1, MOD);
  set<int> odd;
  set<int> even;
  even.insert(0);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    vector<int> ndp(N + 1, MOD);
    if (s[i] != '0') {
      for (int j = 0; j < N; j++) {
        if (dp[j] == MOD) continue;
        ndp[j + 1] = min(ndp[j + 1], dp[j] + (j == dp[j]));
      }
    }
    if (s[i] != '1') {
      for (int j = 1; j <= N; j++) {
        if (dp[j] == MOD) continue;
        ndp[j - 1] = min(ndp[j - 1], dp[j]);
      }
      ndp[0] = min(ndp[0], dp[0] + 1);
    }
    dp = ndp;
  }
  int ans = MOD;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, max(i, dp[i]));
  }
  cout << ans << endl;
  return 0;
}
