#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int k[10], p[10], z[10];
    for(int i = 0; i < 10; i++){
        k[i] = 0;
        z[i] = -1;
        p[i] = -1;
    }
    int brojac = 1;
    char c;
    while((c = getchar()) <= '9' && c >= '0'){
        c = c - '0';
        k[c]++;
        if(k[c] == 1){
            p[c] = brojac;
        }
        z[c] = brojac;
        brojac++;
    }
    int minn = 2000000;
    for(int i = 0; i < 10; i++){
        if(k[i] > 0 && z[i] - p[i] - k[i] + 1 < minn){
            minn = z[i] - p[i] - k[i] + 1;
        }
    }
    if(minn == 0){
        minn = 1;
    }
    cout << minn;
    return 0;
}