#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string S;
  cin >> S;
  vector<char> vec;
  for (int i = 0; i < S.size(); i++) {
    vec.push_back(S[i]);
  }
  vector<int> count0(S.size());
  vector<int> count1(S.size());
  count0[0] = 1;
  count1[0] = 1;
  int ans;
  if (S.size() == 4 && vec[1] == '?' && vec[2] == '?') {
    if (vec[0] == vec[3]) {
      ans = 2;
    } else {
      ans = 1;
    }
  } else {
    for (int i = 1; i < S.size(); i++) {
      if (vec[i] == '0' && vec[i - 1] == '0') {
        count0[i] = count0[i - 1] + 1;
        if (count1[i - 1] > 1) {
          count1[i] = count1[i - 1] - 1;
        } else {
          count1[i] = count1[i - 1];
        }
      } else if (vec[i] == '1' && vec[i - 1] == '1') {
        count1[i] = count1[i - 1] + 1;
        if (count0[i - 1] > 1) {
          count0[i] = count0[i - 1] - 1;
        } else {
          count0[i] = count0[i - 1];
        }
      } else if (vec[i] == '?' && vec[i - 1] == '?') {
        if (count1[i - 1] > 1) {
          count1[i] = count1[i - 1] - 1;
        } else {
          count1[i] = count1[i - 1];
        }
        if (count0[i - 1] > 1) {
          count0[i] = count0[i - 1] - 1;
        } else {
          count0[i] = count0[i - 1];
        }
      } else {
        count0[i] = count0[i - 1];
        count1[i] = count1[i - 1];
      }
    }
    int max0 = 0;
    int max1 = 0;
    for (int i = 0; i < S.size(); i++) {
      if (count0[i] > max0) {
        max0 = count0[i];
      }
    }
    for (int i = 0; i < S.size(); i++) {
      if (count1[i] > max1) {
        max1 = count1[i];
      }
    }
    ans = max(max0, max1);
  }
  cout << ans << endl;
}
