#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) >> 1;
		bool flag = false;
		for (int base = 0; !flag && base < 2; base++) {
			int low = base;
			int high = mid;
			if ((high ^ low) & 1) {
				high--;
			}
			bool ok = high >= low;
			for (int i = 0; ok && i < s.size(); i++) {
				if (s[i] == '1' || low < 1) {
					low++;
				}
				else {
					low--;
				}
				if (s[i] == '0' || high > mid - 1) {
					high--;
				}
				else {
					high++;
				}
				ok = high >= low;
			}
			flag = ok;
		}
		if (flag) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	cout << left << endl;
}