#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int br_1 = 0, br_0 = 0;
    int br_do_0 = 0, br_do_1 = 0;
    int br_posle_0 = 0, br_posle_1 = 0;

    int n = s.size();

    int i = 0, i1;

    while(s[i] == '1') {
        br_do_0++;
        i++;
    }

    i = 0;

    while(s[i] == '0') {
        br_do_1++;
        i++;
    }

    int p_1, p_0;

    for(int i = 0; i < n; ++i)
    {
        if(s[i] == '1') {
            br_1++;
            p_1 = i;
        }
        else {
            br_0++;
            p_0 = i;
        }
    }

    i = p_0 + 1;

    while(s[i] == '1') {
        br_posle_0++;
        i++;
    }

    i = p_1 + 1;

    while(s[i] == '0') {
        br_posle_1++;
        i++;
    }

    int konacno;

    if(br_1 < br_0)
        konacno = br_1 - max(br_do_0, br_posle_0);
    else if(br_0 < br_1)
        konacno = br_0 - max(br_do_1, br_posle_1);
    else
        konacno = br_1 - max(max(br_do_0, br_posle_0), max(br_do_1, br_posle_1));

    cout << konacno << endl;

    return 0;
}