#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  T x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f = c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
namespace run {
const int N = 1e6 + 9;
char s[N];
int n, ans = N;
inline void dfs(int i, int x, int y, int ret) {
  if (ret >= ans) return;
  if (i == n + 1) return ans = min(ret, ans), void();
  if (s[i] != '0') dfs(i + 1, x + 1, max(y - 1, 0), max(ret, x + 1));
  if (s[i] != '1') dfs(i + 1, max(x - 1, 0), y + 1, max(ret, y + 1));
}
int main() {
  scanf("%s", s + 1), n = strlen(s + 1);
  dfs(0, 0, 0, 0);
  printf("%d\n", ans);
  return 0;
}
}  // namespace run
int main() { return run::main(); }
