#include <bits/stdc++.h>
#define K int(1e5)
#define INF int(1e9)
#define MOD (long long)(1e9 + 7)
#define endl "\n"
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

string s;
vector<vector<int>> dp(int(1 << 10) - 1, vector<int>(K));
vector<vector<bool>> vis(int(1 << 10) - 1, vector<bool>(K, 0));

int res(int i = 0, int sum = 0, char lst = 'a'){
    if (i >= s.size()) return 0;
    if (vis[sum][i]) return dp[sum][i];
    int ans = INF;
    if ((sum & (1 << int(s[i] - '0'))) == 0)
        ans = res(i + 1, sum + (1 << int(s[i] - '0'), s[i]));
    if (i > 0) 
        ans = min(ans, res(i + 1, sum + (1 << int(lst - '0'), lst)) + (s[i] != lst));
    if (i < s.size() - 1 && ((sum & (1 << int(s[i + 1] - '0'))) == 0))
        ans = min(ans, res(i + 1, sum + (1 << int(s[i + 1] - '0'), s[i + 1])) + (s[i] != s[i + 1]));
    vis[sum][i] = 1; dp[sum][i] = ans;
    return ans;
}  

void solve(){
    cin >> s;
    cout << res() << endl;
}
 
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
 
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
 
    return 0;
}