#pragma warning(disable:4996)
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define true 39
#define false 0
typedef long long int64;
typedef unsigned long long uint64;
typedef char Bool;

#define one '1'
#define zero '0'
#define que '?'

int strconti(char* s)
{
    if (s == NULL) 
    {
        return -1;
    }
    char c = s[0];
    int i = 1;
    while (1)
    { 
        if (s[i - 1] != c) 
        {
            break;
        }
        i++;
    }
    return i;
}

int strchnum(const char s[], int c)
{
    int i;
    int count = 0;

    for (i = 0; s[i] != '\0'; i++)
        if (s[i] == c)
            count++;
    return (count);
}

int substr(char* t, const char* s, int pos, int len)
{
    if (pos < 0 || len < 0 || len > strlen(s))
        return -1;
    for (s += pos; *s != '\0' && len > 0; len--)
        *t++ = *s++;
    *t = '\0';
    return 0;
}

int avsolute(int v)
{
    return v < 0 ? v * -1 : v;
}

int unbalance(char* s) 
{
    int ls= strlen(s);
    int un = 0;
    char* ss = (char*)malloc(sizeof(char) * ls);
    
    for (int r = 1; r != ls; r++)
    {
        for (int l = 0; l != r; l++)
        {
            substr(ss, s, l, r);
            int tmp = avsolute(strchnum(ss, one) - strchnum(ss, zero));
            if (un < tmp)
            {
                un = tmp;
            }
        }
    }
    return un;
}


int main()
{
	char* s = (char*)malloc(sizeof(char) * 1000000);
	scanf("%s", s);
    int q = strchnum(s, que);
    int on = strchnum(s, one);
    int ze = strchnum(s, zero);

    char c = (on > ze) ? '1' : '0';
    int a = avsolute(on - ze);
    int b = (q - a) / 2;

    for (int i = 0; i != q; i++) 
    {
        char* cp = strchr(s, que);
        int d = strconti(cp);
        if (d > 0) 
        {
            d /= 2;
            *(cp + d) = c;
            *cp = (strchnum(s, one) < strchnum(s, zero)) ? one : zero;
        }
        else
        {
            break;
        }
    }
    strchnum(s, one); strchnum(s, zero);
    printf("%d", unbalance(s));
    return 0;
}