#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	int left = 0, right = s.size();
	while (left < right) {
		int mid = (left + right) / 2;
		// test mid
		int even_low = 0;
		int even_high = mid;
		bool even_ok = even_high >= even_low;
		if (mid % 2) {
			even_high--;
		}
		int odd_low = 1;
		int odd_high = mid;
		bool odd_ok = odd_high >= odd_low;
		if (mid % 2 == 0) {
			odd_high--;
		}
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '1') {
				even_low++;
				even_high++;
				odd_low++;
				odd_high++;
			}
			else if (s[i] == '0') {
				even_low--;
				even_high--;
				odd_low--;
				odd_high--;
			}
			else {
				even_low--;
				even_high++;
				odd_low--;
				odd_high++;
			}
			while (even_low < 0) {
				even_low += 2;
			}
			while (even_high > mid) {
				even_high -= 2;
			}
			while (odd_low < 0) {
				odd_low += 2;
			}
			while (odd_high > mid) {
				odd_high -= 2;
			}
			if (even_high < even_low) {
				even_ok = false;
			}
			if (odd_high < odd_low) {
				odd_ok = false;
			}
		}
		if (odd_ok || even_ok) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	cout << left << endl;
}