#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {{x, y}, z}
/*
int arr[100001], tree[400004];

void build(int node, int st, int en)
{
    if (st > en) return;
    if (st == en)
    {
        tree[node] = arr[st];
        return;
    }
    int mid = (st+en)/2;
    build(2*node, st, mid);
    build(2*node + 1, mid + 1, en);
    tree[node] = tree[2*node] ^ tree[2*node + 1];
}

void update(int node, int st, int en, int shemal, int yemeen, int val)
{

    if (st > en || st > yemeen || en < shemal) return;

    if (shemal <= st && en <= yemeen)
    {
        tree[node] = val;
        return;
    }

    int mid = (st+en)/2;

    update(2*node, st, mid, shemal, yemeen, val);
    update(2*node + 1, mid + 1, en, shemal, yemeen, val);
    tree[node] = tree[2*node] ^ tree[2*node + 1];
}

bool visited[100100];*/

bool check(string x)
{
    rep(i, 0, sz(x)-1)
    {
        if (x[i] != x[i+1]) return true;
    }
    return false;
}

int solve(string x, char a)
{
    int cnt = 0;
    while(check(x))
    {
        rep(i, 0, sz(x)-1)
        {
            if (x[i] == a) continue;
            if (x[i+1] == a) x[i] = a;
        }
        cnt++;
        x.pop_back();
    }
    return cnt;
}

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    /*int n;
    cin >> n;
    map<int, deque<int> > mp;
    set< pii > st;
    rep(i, 0, n) cin >> arr[i];
    vi temp(n);
    int idx = 0, match = 0, cnt = 0;
    rep(i, 0, n)
    {
        cin >> temp[i];
        if (temp[i] == arr[i]) match++, visited[i] = true;
        else
            mp[temp[i]].push_back(i);
    }
    build(1, 0, n-1);
    while(true)
    {
        if (idx == n && match != n)
        {
            cout << -1;
            return 0;
        }
        if (match == n)
        {
            cout << cnt;
            return 0;
        }
        int rakam = tree[1];
        if (mp[rakam].empty())
        {
            while(visited[idx]) idx++;
            arr[idx] = rakam;
            update(1, 0, n-1, idx, idx, rakam);
            visited[idx] = true;
        }
        else
        {
            int x = mp[rakam].front();
            mp[rakam].pop_front();
            arr[x] = rakam;
            visited[x] = true;
            match++;
            update(1, 0, n-1, x, x, rakam);
        }
        rep(i, 0, n) cout << arr[i] << " ";
        cout << endl;
        cout << "MATCH: " << match << endl;
        cnt++;
    }*/


    string x;
    cin >> x;
    map<char, bool> mp;
    rep(i, 0, sz(x)) mp[x[i]] = true;
    int mn = INT_MAX;
    erep(i, 'a', 'z')
    {
        if (mp[i])
        {
            mn = min(mn, solve(x, i));
        }
    }
    cout << mn;
    return 0;
}


Measured memory_bytes: 256