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

typedef long long ll;

int n, numDig[maxn][11];
string s;
ll ans;
ll dp[maxn][1<<10];
bool ok;

void solveC0(){
	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]);
	}
}

int inCost(int i, int j, int c){
	// [i, j]
	int res = numDig[j][c];
	if(i){
		res -= numDig[i-1][c];
	}
	res = (j-i+1)-res;
	return res;
}

void solveC1(){
	for(int i = 0; i < n; ++i){
		numDig[i][s[i]-'0'] = 1;
		if(i){
			for(int c = 0; c < 10; ++c){
				numDig[i][c] += numDig[i-1][c];
			}
		}
	}
	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);
					// }
					int l = i, r = n-1;
					while(l <= r){

						int mid = (l+r)/2;//cerr << l << ' ' << r << ' ' << dp[mid+1][mask^(1<<c)] << '\n';
						dp[i][mask] = min(dp[i][mask], dp[mid+1][mask^(1<<c)] + inCost(i, mid, c));
						if(inCost(i, mid, c) > dp[mid+1][mask^(1<<c)]){
							r = mid-1;
						} else {
							l = mid+1;
						}
					}
				}
			}
		}
		ans = min(ans, dp[0][mask]);
	}
}

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

	n=s.length();
	ok = ((count(s.begin(), s.end(), '1')+count(s.begin(), s.end(), '0')) == n);
	if(ok or n <= 100){
		solveC0();
	} else {
		solveC1();
	}
	cout << ans;
}