#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fi first
#define se second
#define ld long double
#define MAXC 10000000
#define N_MAX 100010

using namespace std;
vector<pair<int,char>>al[N_MAX];

void resi2(string &s) {
    int n = s.length();
    
    if ( n > 7 ) {
        cout << n/4 << endl ;
        return;
    }
    int best = INT_MAX;
    for (int i = 0 ; i <= 1000000 ; i++ ) {
        int cnt = 0 ;
        bool video[10];
        memset(video,0,sizeof(video));
        
        string t = to_string(i);
        if ( t.size() > n ) break;
        while(t.size() < n) t = '0' + t;
        
        video[t[0]-'0']++;
        for (int j = 1 ; j < n ; j++ ) {
            int c = t[j]-'0';
            if ( video[c] && t[j-1] != t[j] ){
                goto sledeci;
            }
            video[c]++;
        }
        
        for (int j = 0 ; j < n ; j++ ) {
            if ( s[j] != t[j] ) cnt++;
        }
        
        best = min(best,cnt);
        //cout << i << ' ' << cnt << endl ;
        
        sledeci: continue;
    }
    
    cout << best << endl ;
}

void resi1(string &s) {
	int n = s.length();

	vector<int>bj(n+1);
	bj[0]=0;
	for (int i = 0;  i < n ; i++ ) {
		bj[i+1] = bj[i];
		if ( s[i] == '1') bj[i+1]++;
	}

	int res = INT_MAX;

	for (int i = 0 ; i <= n ; i++ ) {
		int temp = i-bj[i];//prvo jedinice 
		//cout << temp << ' ';
		temp += bj[n]-bj[i];//drugo nule
        //cout << temp << ' ';
        
        
		int temp2 = bj[i];//prvo nule
		//cout << temp2 << ' ';
		temp2+= n-i-(bj[n]-bj[i]);
		//cout << temp2 << endl ;
		res = min(res,min(temp,temp2));
	}

	cout << res<< endl ;

}

void solve() {
	string s;
	cin >>s ;
	bool okej = 1 ;
	for (auto u : s) {
		if ( u> '1' ) okej=0;
	}

	if ( okej ) {
		resi1(s);
		return;
	}
	
    resi2(s);
} 


int main () {
 	
 	
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

 
    int t =1;
    //cin >>t ;
    while(t--) 
        solve();
}