#include <bits/stdc++.h>
#define maxn 100010
using namespace std;

typedef long long ll;

int n;
ll ans;
ll dp[maxn][1<<10];

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	string s;
	cin >> s;
	n=s.length();
	bool ok = ((count(s.begin(), s.end(), '1')+count(s.begin(), s.end(), '0')) == n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < (1<<10); ++j){
			dp[i][j] = 1e18;
		}
	}
	for(int i = 0; i < (1<<10); ++i){
		dp[n][i] = 0;
	}
	ans = 1e18;
	for(int mask = 0; mask < (1<<10); ++mask){
		if(mask > 3 and ok){
			break;
		}
		for(int i = n-1; i >= 0; --i){
			for(int c = 0; c < 10; ++c){
				if(c > 1 and ok){
					break;
				}
				if(mask&(1<<c)){
					int numC = 0;
					for(int j = i; j < n; ++j){
						numC += ((s[j]-'0')!=c);
						dp[i][mask] = min(dp[i][mask], dp[j+1][mask^(1<<c)] + numC);
					}
				}
			}
		}
		ans = min(ans, dp[0][mask]);
	}
	cout<<ans;
}