#include <Foundation/Foundation.h>
int main() {
    @autoreleasepool{
        char s[102];
        scanf("%s",s);
        long n = strlen(s);
        if(n==1){
            puts("0");
            return 0;
        }
        NSMutableSet *set = [NSMutableSet set];
        NSMutableArray *S = [NSMutableArray array];
        for(long i=0;i<n;i++){
            [set addObject:@(s[i])];
            [S addObject:@(s[i])];
        }
        long ans = NSIntegerMax;
        for(NSNumber *c in set){
            char dest = [c charValue];
            NSMutableArray *T = [NSMutableArray arrayWithArray:S];
            long result = 0;
            while([[T valueForKeyPath:@"@distinctUnionOfObjects.self"] count] > 1){
                NSMutableArray *U = [NSMutableArray array];
                for(long i=0;i<[T count]-1;i++){
                    char x = [[T objectAtIndex:i] charValue];
                    char y = [[T objectAtIndex:i+1] charValue];
                    if(x==dest || y==dest){
                        [U addObject:@(dest)];
                    }else{
                        [U addObject:@(x)];
                    }
                }
                result++;
                T = U;
            }
            ans = MIN(ans, result);
        }
        printf("%ld\n",ans);
    }
}
