#include <bits/stdc++.h>
using namespace std;
int unb(string s) {
  int u_max = 0;
  for (int r = 0; r < s.length(); ++r) {
    for (int l = r; l < s.length(); ++l) {
      int u0 = 0, u1 = 0;
      for (int i = r; i <= l; ++i) {
        if (s[i] == '0') u0++;
        if (s[i] == '1') u1++;
      }
      int u = (u0 > u1 ? u0 - u1 : u1 - u0);
      if (u_max < u) u_max = u;
    }
  }
  return u_max;
}
int main() {
  string S;
  cin >> S;
  cerr << S << endl;
  if (S[0] == '?') {
    string s0 = "0" + S, s1 = "1" + S;
    cerr << "s0:" << s0 << endl;
    cerr << "s1:" << s1 << endl;
    for (int i = 1; i < s0.length(); ++i) {
      if (s0[i] == '?') {
        s0[i] = (s0[i - 1] == '1' ? '0' : '1');
      }
      if (s1[i] == '?') {
        s1[i] = (s1[i - 1] == '1' ? '0' : '1');
      }
    }
    int u0 = unb(s0.substr(1, S.length()));
    cerr << "u0=" << u0 << endl;
    int u1 = unb(s1.substr(1, S.length()));
    cerr << "u1=" << u1 << endl;
    int u = (u0 > u1 ? u1 : u0);
    cout << u << endl;
  } else {
    for (int i = 1; i < S.length(); ++i) {
      if (S[i] == '?') {
        S[i] = (S[i - 1] == '1' ? '0' : '1');
      }
    }
    cout << unb(S) << endl;
  }
  return 0;
}
