#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN = 1e9;
const ll mod = 1e9 + 7;
bool check(string s)
{
    vector<int> c(10, 0);
    c[s[0] - '0']++;
    for (int i = 1; i < s.length(); i++)
    {
        if (s[i] != s[i - 1])
            c[s[i] - '0']++;
    }
    for (int i = 0; i < 10; i++)
    {
        if (c[i] > 1)
            return 0;
    }
    return 1;
}

int main()
{
    //brute
    string s;
    cin >> s;
    if (s.length() < 3)
        cout << 0;
    else if (s.length() == 3)
    {
        if (s[0] != s[2])
            cout << 0;
        else
        {
            if (s[0] == s[1])
                cout << 0;
            else
                cout << 1;
        }
    }
    else
    {
        vector<int> c(10, 0);
        for (int i = 0; i < s.length(); i++)
        {
            c[s[i] - '0']++;
        }
        if (c[0] + c[1] == s.length())
        {
            vector<int> g0, g1;
            int curr = 1;
            for (int i = 1; i <= s.length() - 1; i++)
            {
                if (s[i] != s[i - 1])
                {
                    if (s[i - 1] == '0')
                        g0.pb(curr);
                    else
                        g1.pb(curr);
                    curr = 1;
                }
                else
                    curr++;
            }
            if (s[s.length() - 1] == '0')
                g0.pb(curr);
            else
                g1.pb(curr);
            sort(g0.rbegin(), g0.rend());
            sort(g1.rbegin(), g1.rend());
            if (c[0] == g0[0])
                cout << c[1] - g1[0];
            else if (c[1] = g0[1])
                cout << c[0] - g0[0];
            else
                cout << min(c[0] - g0[0], c[1] - g1[0]);
        }
        else
            cout << 0;
    }
    return 0;
}