#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	Node(int id=0, int vj=0): id(id), vj(vj) {}
	bool operator < (const Node& rhs) const {
		if (vj != rhs.vj) return vj < rhs.vj;
		return id < rhs.id;
	}
} vRight[maxn];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		memset(left, 0, sizeof(left));
		memset(right, 0, sizeof(right));
		memset(vRight, 0, sizeof(vRight));
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1 ? 1 : 0);
			pre_right[i] = pre_right[i-1] + (right[i] == 1 ? 1 : 0);
		}
		for (int i = 0; i <= n; i++) {
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight, vRight+n+1);

		int ans = 2*n;
		for (int i = 0; i <= n; i++) {
			Node vLeft(i, i-2*pre_left[i]);
			int k = upper_bound(vRight, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	Node(int id=0, int vj=0): id(id), vj(vj) {}
	bool operator < (const Node& rhs) const {
		return vj < rhs.vj;
	}
} vRight[maxn];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		memset(left, 0, sizeof(left));
		memset(right, 0, sizeof(right));
		memset(vRight, 0, sizeof(vRight));
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1);
			pre_right[i] = pre_right[i-1] + (right[i] == 1);
		}
		for (int i = 0; i <= n; i++) {
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight, vRight+n+1);

		int ans = 2*n;
		for (int i = 0; i <= n; i++) {
			Node vLeft(i, i-2*pre_left[i]);
			int k = upper_bound(vRight, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	bool operator < (const Node& rhs) const {
		return vj < rhs.vj;
	}
} vRight[maxn];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1);
			pre_right[i] = pre_right[i-1] + (right[i] == 1);
		}
		for (int i = 0; i <= n; i++) {
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight+1, vRight+n+1);

		int ans = 2*n;
		for (int i = 0; i <= n; i++) {
			Node vLeft = {i, i-2*pre_left[i]};
			int k = upper_bound(vRight+1, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	Node(int id=0, int vj=0): id(id), vj(vj) {}
	bool operator < (const Node& rhs) const {
		return vj < rhs.vj;
	}
} vRight[maxn];

bool cmp(const Node& A, const Node& B) {
	if (A.vj != B.vj) return A.vj < B.vj;
	return A.id < B.id;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		memset(left, 0, sizeof(left));
		memset(right, 0, sizeof(right));
		memset(vRight, 0, sizeof(vRight));
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1 ? 1 : 0);
			pre_right[i] = pre_right[i-1] + (right[i] == 1 ? 1 : 0);
		}
		for (int i = 0; i <= n; i++) {
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight, vRight+n+1, cmp);

		int ans = 2*n;
		for (int i = 0; i <= n; i++) {
			Node vLeft(i, i-2*pre_left[i]);
			int k = upper_bound(vRight, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	bool operator < (const Node& rhs) const {
		return vj < rhs.vj;
	}
} vRight[maxn];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1);
			pre_right[i] = pre_right[i-1] + (right[i] == 1);
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight+1, vRight+n+1);

		int ans = 2*n;
		for (int i = 1; i <= n; i++) {
			Node vLeft = {i, i-2*pre_left[i]};
			int k = upper_bound(vRight+1, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    scanf("%d", &t);

    while (t--) {
        int n, ones = 0, twos = 0;
        scanf("%d", &n);

        vector <int> left(n), right(n), accLeft(n+1, -1), accRight(n+1, -1);
        for (int i = 0; i < n; ++i) {
            scanf("%d", &left[i]);
            if (left[i] == 1) ++ones;
            else ++twos;
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", &right[i]);
            if (right[i] == 1) ++ones;
            else ++twos;
        }

        if (twos > ones) {
            for (int i = 0; i < n; ++i) {
                if (left[i] == 1) ++left[i];
                else --left[i];
            }
            for (int i = 0; i < n; ++i) {
                if (right[i] == 1) ++right[i];
                --right[i];
            }
        }

        int diff = ones - twos, ans = 4*n;
        if (!diff) {
            printf("0\n");
            continue;
        }
//         printf("diff = %d\n", diff);
        for (int i = n-1; i >= 0; --i) {
            if (i == n-1) left[i] = left[i]==1?1:-1;
            else left[i] = left[i+1] + (left[i]==1?1:-1);

            if (left[i] >= 0 and accLeft[left[i]] == -1) accLeft[left[i]] = i;
//             printf("%d ", left[i]);
        }
//         printf("\n");
        for (int i = 0; i < n; ++i) {
            if (i) right[i] = right[i-1] + (right[i]==1?1:-1);
            else right[i] = right[i]==1?1:-1;

            if (right[i] >= 0 and accRight[right[i]] == -1) accRight[right[i]] = i+n;
//             printf("%d ", right[i]);
        }/*
        printf("\n");
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accLeft[i]);
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accRight[i]);
        printf("\n");*/
        for (int i = 0; i <= min(n, diff); ++i) {
            if ((!i or i == diff) and diff <= n) {
                if (accRight[diff] != -1) ans = min(ans, accRight[diff]-n+1);
                if (accLeft[diff] != -1) ans = min(ans, n-accLeft[diff]);
//                 printf("%d-%d = %d\n", n, accLeft[diff], n-accLeft[diff]);
            }
            else {
                if (diff-i <= n and accLeft[i] != -1 and accRight[diff-i] != -1)
                    ans = min(ans, accRight[diff-i]-accLeft[i]+1);
                if (diff-i <= n and accLeft[diff-i] != -1 and accRight[i] != -1)
                    ans = min(ans, accRight[i]-accLeft[diff-i]+1);
            }
//             printf("%d: %d\n", i, ans);
        }

        printf("%d\n", ans);
    }
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    scanf("%d", &t);

    while (t--) {
        int n, ones = 0, twos = 0;
        scanf("%d", &n);

        vector <int> left(n), right(n), accLeft(n+1, -1), accRight(n+1, -1);
        for (int i = 0; i < n; ++i) {
            scanf("%d", &left[i]);
            if (left[i] == 1) ++ones;
            else ++twos;
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", &right[i]);
            if (right[i] == 1) ++ones;
            else ++twos;
        }

        if (twos > ones) {
            for (int i = 0; i < n; ++i) {
                if (left[i] == 1) ++left[i];
                else --left[i];
            }
            for (int i = 0; i < n; ++i) {
                if (right[i] == 1) ++right[i];
                --right[i];
            }
        }

        int diff = ones - twos, ans = 4*n;
        if (!diff) {
            printf("0\n");
            continue;
        }
//         printf("diff = %d\n", diff);
        for (int i = n-1; i >= 0; --i) {
            if (i == n-1) left[i] = left[i]==1?1:-1;
            else left[i] = left[i+1] + (left[i]==1?1:-1);

            if (left[i] >= 0 and accLeft[left[i]] == -1) accLeft[left[i]] = i;
//             printf("%d ", left[i]);
        }
//         printf("\n");
        for (int i = 0; i < n; ++i) {
            if (i) right[i] = right[i-1] + (right[i]==1?1:-1);
            else right[i] = right[i]==1?1:-1;

            if (right[i] >= 0 and accRight[right[i]] == -1) accRight[right[i]] = i+n;
//             printf("%d ", right[i]);
        }/*
        printf("\n");
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accLeft[i]);
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accRight[i]);
        printf("\n");*/
        for (int i = 0; i <= n; ++i) {
            if (diff-i <= n and accRight[diff-i] != -1 and accLeft[i] != -1) ans = min(ans,
abs(accRight[diff-i]-accLeft[i])+1);
            if (diff-i <= n and accRight[i] != -1 and accLeft[diff-i] != -1) ans = min(ans,
abs(accRight[i]-accLeft[diff-i])+1);

//             printf("%d: %d\n", i, ans);
        }

        printf("%d\n", ans);
    }
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t;
    scanf("%d", &t);

    while (t--) {
        int n, ones = 0, twos = 0;
        scanf("%d", &n);

        vector <int> left(n), right(n), accLeft(n+1, -1), accRight(n+1, -1);
        for (int i = 0; i < n; ++i) {
            scanf("%d", &left[i]);
            if (left[i] == 1) ++ones;
            else ++twos;
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", &right[i]);
            if (right[i] == 1) ++ones;
            else ++twos;
        }

        if (twos > ones) {
            for (int i = 0; i < n; ++i) {
                if (left[i] == 1) ++left[i];
                else --left[i];
            }
            for (int i = 0; i < n; ++i) {
                if (right[i] == 1) ++right[i];
                --right[i];
            }
        }

        int diff = ones - twos, ans = 4*n;
        if (!diff) {
            printf("0\n");
            continue;
        }
//         printf("diff = %d\n", diff);
        for (int i = n-1; i >= 0; --i) {
            if (i == n-1) left[i] = left[i]==1?1:-1;
            else left[i] = left[i+1] + (left[i]==1?1:-1);

            if (left[i] >= 0 and accLeft[left[i]] == -1) accLeft[left[i]] = i;
//             printf("%d ", left[i]);
        }
//         printf("\n");
        for (int i = 0; i < n; ++i) {
            if (i) right[i] = right[i-1] + (right[i]==1?1:-1);
            else right[i] = right[i]==1?1:-1;

            if (right[i] >= 0 and accRight[right[i]] == -1) accRight[right[i]] = i+n;
//             printf("%d ", right[i]);
        }/*
        printf("\n");
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accLeft[i]);
        printf("\n");
        for (int i = 0; i <= n; ++i) printf("%d ", accRight[i]);
        printf("\n");*/
        for (int i = 0; i <= n; ++i) {
            if ((!i or i == diff) and diff <= n) {
                ans = min(ans, accRight[diff]-n+1);
                ans = min(ans, n-accLeft[diff]);
                continue;
            }
            if (diff-i <= n and accRight[diff-i] != -1 and accLeft[i] != -1) ans = min(ans,
abs(accRight[diff-i]-accLeft[i])+1);
            if (diff-i <= n and accRight[i] != -1 and accLeft[diff-i] != -1) ans = min(ans,
abs(accRight[i]-accLeft[diff-i])+1);

//             printf("%d: %d\n", i, ans);
        }

        printf("%d\n", ans);
    }
}


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

int main() {
    string S; cin >> S;
    int Answ = 1000000;

    map<char, bool> Map;
    vector<char> Letters;
    bool NonValid = 0;
    for (int i = 0; i < S.size(); i++) {
        if (Map[S[i]] == 0) {
            Map[S[i]] = 1;
            Letters.push_back(S[i]);
        }
    }
    for (int i = 0; i < Letters.size(); i++) {
        int Gap = -1;
        int MaxGap = 0;
        for (int j = 0; j < S.size(); j++) {
            if (S[j] != Letters[i]){
                Gap++;
                MaxGap = max(MaxGap, Gap);
            }
            else
                Gap = 0;
        }
        Answ = min(MaxGap, Answ);
    }

    cout << Answ + 1;

/*
    while (1) {
        map<char, bool> Map;
        map<char, int> Was;
        vector<char> Letters;
        int Counter = 1;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
            Was[S[i]] = Counter;
            Counter++;
        }

        Counter = Answ;
        for (int i = Answ; i < S.size(); i++) {
            for (int j = 0; j < Letters.size(); j++) {
                Was[S[j]]--;
            }
            if (Map[S[i]] == 1) {
                Was[S[i]] = Counter;
            }
            for (int j = 0; j < Letters.size(); j++) {
                if (Was[S[j]] == 0)
                    Map[S[j]] = 0;
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    */
    /*
    while (1) {
        map<char, bool> Map;
        vector<char> Letters;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Letters.size(); k++) {
                if (Temp[Letters[k]] == 0) {
                    Map[Letters[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;
    */
    return 0;
}


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

int main() {
    string S; cin >> S;
    int Answ = 1;
    while (1) {
        map<char, bool> Map;
        vector<char> Letters;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }

        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Letters.size(); k++) {
                if (Temp[Letters[k]] == 0) {
                    Map[Letters[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;

    return 0;
}


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

int main() {
    string S; cin >> S;
    int Answ = 1;

    while (1) {
        map<char, bool> Map;
        map<char, int> Was;
        vector<char> Letters;
        int Counter = 1;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
            Was[S[i]] = Counter;
            Counter++;
        }

        Counter = Answ;
        for (int i = Answ; i < S.size(); i++) {
            for (int j = 0; j < Letters.size(); j++) {
                Was[S[j]]--;
            }
            if (Map[S[i]] == 1) {
                Was[S[i]] = Counter;
            }
            for (int j = 0; j < Letters.size(); j++) {
                if (Was[S[j]] == 0)
                    Map[S[j]] = 0;
            }
        }
        bool Is = 1;
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 0) {
                Is = 0;
                break;
            }
        }
        if (Is == 1) {
            cout << Answ;
            return 0;
        }
        Answ++;
    }
    /*
    while (1) {
        map<char, bool> Map;
        vector<char> Letters;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }

        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Letters.size(); k++) {
                if (Temp[Letters[k]] == 0) {
                    Map[Letters[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;
    */
    return 0;
}


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

int main() {
    string S; cin >> S;
    long int Answ = 1000000000;

    map<char, bool> Map;
    vector<char> Letters;
    bool NonValid = 0;
    for (long int i = 0; i < S.size(); i++) {
        if (Map[S[i]] == 0) {
            Map[S[i]] = 1;
            Letters.push_back(S[i]);
        }
    }
    for (long int i = 0; i < Letters.size(); i++) {
        long int Gap = -1;
        long int MaxGap = 0;
        for (long int j = 0; j < S.size(); j++) {
            if (S[j] != Letters[i]){
                Gap++;
                MaxGap = max(MaxGap, Gap);
            }
            else
                Gap = 0;
        }
        Answ = min(MaxGap, Answ);
    }

    cout << Answ + 1;

/*
    while (1) {
        map<char, bool> Map;
        map<char, int> Was;
        vector<char> Letters;
        int Counter = 1;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
            Was[S[i]] = Counter;
            Counter++;
        }

        Counter = Answ;
        for (int i = Answ; i < S.size(); i++) {
            for (int j = 0; j < Letters.size(); j++) {
                Was[S[j]]--;
            }
            if (Map[S[i]] == 1) {
                Was[S[i]] = Counter;
            }
            for (int j = 0; j < Letters.size(); j++) {
                if (Was[S[j]] == 0)
                    Map[S[j]] = 0;
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    */
    /*
    while (1) {
        map<char, bool> Map;
        vector<char> Letters;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Letters.size(); k++) {
                if (Temp[Letters[k]] == 0) {
                    Map[Letters[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;
    */
    return 0;
}


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

int main() {
    string S; cin >> S;
    long long int Answ = 100000000000;

    map<char, bool> Map;
    vector<char> Letters;
    bool NonValid = 0;
    for (int i = 0; i < S.size(); i++) {
        if (Map[S[i]] == 0) {
            Map[S[i]] = 1;
            Letters.push_back(S[i]);
        }
    }
    for (int i = 0; i < Letters.size(); i++) {
        int Gap = -1;
        int MaxGap = 0;
        for (int j = 0; j < S.size(); j++) {
            if (S[j] != Letters[i]){
                Gap++;
                MaxGap = max(MaxGap, Gap);
            }
            else
                Gap = 0;
        }
        Answ = min(MaxGap, Answ);
    }

    cout << Answ + 1;

/*
    while (1) {
        map<char, bool> Map;
        map<char, int> Was;
        vector<char> Letters;
        int Counter = 1;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
            Was[S[i]] = Counter;
            Counter++;
        }

        Counter = Answ;
        for (int i = Answ; i < S.size(); i++) {
            for (int j = 0; j < Letters.size(); j++) {
                Was[S[j]]--;
            }
            if (Map[S[i]] == 1) {
                Was[S[i]] = Counter;
            }
            for (int j = 0; j < Letters.size(); j++) {
                if (Was[S[j]] == 0)
                    Map[S[j]] = 0;
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    */
    /*
    while (1) {
        map<char, bool> Map;
        vector<char> Letters;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 0) {
                Map[S[i]] = 1;
                Letters.push_back(S[i]);
            }
        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Letters.size(); k++) {
                if (Temp[Letters[k]] == 0) {
                    Map[Letters[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Letters.size(); i++) {
            if (Map[Letters[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;
    */
    return 0;
}


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

int main() {
    string S; cin >> S;
    int Answ = 1;
    while (1) {
        map<char, bool> Map;
        bool NonValid = 0;
        for (int i = 0; i < Answ; i++) {
            Map[S[i]] = 1;
        }

        for (int i = 0; i <= S.size() - Answ; i++) {
            map<char, bool> Temp;
            for (int j = i; j < i + Answ; j++) {
                Temp[S[j]] = 1;
            }
            for (int k = 0; k < Answ; k++) {
                if (Temp[S[k]] == 0) {
                    Map[S[k]] = 0;
                }
            }
        }
        for (int i = 0; i < Answ; i++) {
            if (Map[S[i]] == 1) {
                cout << Answ;
                return 0;
            }
        }
        Answ++;
    }
    cout << Answ;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    //ll maxx=0;
    rep(i,0,27)
    {
        if(arr[i].size()>0)
        {
        ll prev=0;
        ll maxx=0;
        //char curr=(char)((int)i+'a');
        for(ll k=0;k<arr[i].size();k++)
        {
            ll ele=arr[i][k];
            maxx=max(maxx,ele-prev);
            prev=ele;
        }
        maxx=max(maxx,(ll)s1.length()-prev+1);
        minn=min(minn,maxx);
        }
    }
    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out (char)(i+'a')<<"   "<<temp;nl
            //out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
            out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<start+k and arr[i][arr[i].size()-1]+k>s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out (char)(i+'a')<<"   "<<temp;nl
            //out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
            //out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<start+k and arr[i][arr[i].size()-1]+k>s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include "Header.h"
//#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out (char)(i+'a')<<"   "<<temp;nl
            //out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
           // out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>=s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out (char)(i+'a')<<"   "<<temp;nl
            //out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
            //out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out (char)(i+'a')<<"   "<<temp;nl
            //out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
           // out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>=s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            out (char)(i+'a')<<"   "<<temp;nl
            out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
           // out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>=s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }

            }

        }
    }

    out minn;
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            //out "i "<<temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
           // out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>=s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;nl
}


#include<bits/stdc++.h>
using namespace std;
#define in cin
//#include <fstream>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define cnt(v,a) (int)count(v.begin(),v.end(),a)
#define err(v) v.erase(v.begin(),v.end());
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define out cout<<
#define nl cout<<endl;
#define setbit(p) __builtin_popcountll(p)
#define totalbit(p) (int)(log2(p)+1)
#define myfill(a,b,n) rep(i,0,n){a[i]=b;}
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,n) for(auto i=a;i<n;i++)
#define fi(it,mp) for(auto it=mp.begin();it!=mp.end();it++)
#define sortv(v) sort(v.begin(),v.end())
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define max3(a,b,c) max(a,max(b,c))
#define prnt(v) rep(i,0,v.size()){out v[i]<<" ";}
#define fileopen //ifstream in ("/Users/kashishmiglani/Desktop/iCloud Drive (Archive) - 1/Desktop/practice/inputfile") ;
#define fileclose //ofstream printfile("/Users/kashishmiglani/Desktop/op1.txt");
#define MOD 1000000007

//const int N=500005;ll fa[N],ec[N],sz[N]; inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//ll fast_multiply(ll a, ll b){ll result = 0;while(b > 0){ll lastDigit = b&1;if(lastDigit > 0){result=(result + a);}a = a << 1; b = b >> 1;}return result; }
//ll power(ll a,ll b){ll ans=1;while(b){if(b%2==1){ ans=(ans*a)%MOD;} b=b/2; a=(a*a)%MOD; } return ans;}
typedef long long ll;
typedef string str;
typedef pair<ll,ll> ii;
typedef pair<ii,ii> pi;
typedef pair<string,ll> si;
typedef pair<ll,char> ic;
typedef pair<ll,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector<ic> vic;
typedef vector <ll> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,ll> msi;
typedef map <string,string> mss;
typedef map <ll,ll> mii;
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b%a, a);}
vi v1;
vi arr[30];
int main()
{

    fast
    str s1,s2;
    ll inp,n,a,b,t,q,k,m,x,y;
    in>>s1;
    rep(i, 0, s1.length())
    {
        int ele=s1[i]-'a';
        arr[ele].pb(i+1);
    }
    ll minn=s1.length();
    rep(i,0,27)
    {
        if(arr[i].size()==1)
        {
            ll temp=arr[i][0];
            out (char)(i+'a')<<"   "<<temp;nl
            out temp<<"--"<<s1.length()-temp;nl
            minn=min(minn,(ll)(max((ll)(s1.length()-temp+1),temp)));
        }

        else if(arr[i].size()>0)
        {
            bool fl=true;
           // out " i "<<i;nl
            for(ll k=arr[i][0];k<s1.length()-1;k++)
            {
                //out "   k "<<k;nl
                ll start=arr[i][0];
                fl=true;
                for(int j=1;j<arr[i].size()-1;j++)
                {
                    if(arr[i][j]<=start+k)
                    {
                        start=arr[i][j];
                    }
                    else
                    {
                        fl=false;
                        break;
                    }
                }
                if(arr[i][arr[i].size()-1]<=start+k and arr[i][arr[i].size()-1]+k>=s1.length())
                {
                    if(fl)
                    {
                       // out "           kkkk "<<k;nl
                        minn=min(minn,k);
                        break;
                    }
                }
            }
        }
    }
    out minn;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] == a.size() - k + 1 || c[i] == a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = a.size() + 1, m = 0;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 25001, m = 0;
	if(a.size() < 50001)
		l = a.size() + 1;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;

bool ist(int k)
{
	set<char> pos;
	set<char> pos2;
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (i == 0)
				pos.insert(a[j]);
			else
			{
				if (i % 2 == 1)
				{
					if (pos.find(a[j]) != pos.end())
						pos2.insert(a[j]);
				}
				else
				{
					if (pos2.find(a[j]) != pos2.end())
						pos.insert(a[j]);
				}
			}
		}
		if (i % 2 == 1)
			pos.clear();
		else
			pos2.clear();
	}
	if (i % 2 == 0)
	{
		if (pos2.size() >= 1)
			return true;
		else
			return false;
	}
	else
	{
		if (pos.size() >= 1)
			return true;
		else
			return false;
	}
}

int main()
{
	cin >> a;
	int s = -1, l = a.size() + 1, m = 0;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 50001, m = 0;
	if(a.size() < 50001)
		l = a.size() + 1;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int maxi = 1e7, mt;
string a;
vector<int> s[26 + 5], c[26 + 5];

int main()
{
	ios::sync_with_stdio(false);
	cin >> a;
	for (int i = 0; i < 31; i++)
	{
		s[i].push_back(-1);
		c[i].push_back(-1);
	}
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] >= 'a' && a[i] <= 'z')
			s[a[i] - 'a'].push_back(i);
		else
			s[a[i] - 'A'].push_back(i);
	}
	for (int i = 0; i < 31; i++)
	{
		mt = 0;
		if(s[i].size() > 1)
		s[i].push_back(a.size());
		for (int j = 1; j < s[i].size(); j++)
		{
			mt = max(mt, s[i][j] - s[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
		mt = 0;
		if(c[i].size() > 1)
		c[i].push_back(a.size());
		for (int j = 1; j < c[i].size(); j++)
		{
			mt = max(mt, c[i][j] - c[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
	}
	if (maxi == 1e7)
		cout << a.size();
	else
		cout << maxi;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 100, m = 0;
	if(a.size() < 100)
		l = a.size();
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 5000, m = 0;
	if(a.size() < 100)
		l = a.size() + 1;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int maxi = 1e7, mt;
string a;
vector<int> s[26 + 5], c[26 + 5];

int main()
{
	ios::sync_with_stdio(false);
	cin >> a;
	for (int i = 0; i < 31; i++)
	{
		s[i].push_back(-1);
		c[i].push_back(-1);
	}
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] >= 'a' && a[i] <= 'z')
			s[a[i] - 'a'].push_back(i);
		else
			s[a[i] - 'A'].push_back(i);
	}
	for (int i = 0; i < 31; i++)
	{
		mt = 0;
		if (s[i].size() > 1)
			s[i].push_back(a.size());
		for (int j = 1; j < s[i].size(); j++)
		{
			mt = max(mt, s[i][j] - s[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
		mt = 0;
		if (c[i].size() > 1)
			c[i].push_back(a.size());
		for (int j = 1; j < c[i].size(); j++)
		{
			mt = max(mt, c[i][j] - c[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
		if (maxi == 1)
			break;
	}
	if (maxi == 1e7)
		cout << a.size();
	else
		cout << maxi;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 53, m = 0;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = a.size() + 1, m = 0;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 100, m = 0;
	if(a.size() < 100)
		l = a.size() + 1;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int maxi = 1e7, mt;
string a;
vector<int> s[26 + 5], c[26 + 5];

int main()
{
	cin >> a;
	for (int i = 0; i < 31; i++)
	{
		s[i].push_back(-1);
		c[i].push_back(-1);
	}
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] >= 'a' && a[i] <= 'z')
			s[a[i] - 'a'].push_back(i);
		else
			s[a[i] - 'A'].push_back(i);
	}
	for (int i = 0; i < 31; i++)
	{
		mt = 0;
		s[i].push_back(a.size());
		for (int j = 1; j < s[i].size(); j++)
		{
			mt = max(mt, s[i][j] - s[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
		mt = 0;
		c[i].push_back(a.size());
		for (int j = 1; j < c[i].size(); j++)
		{
			mt = max(mt, c[i][j] - c[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
	}
	if (maxi == 1e7)
		cout << a.size();
	else
		cout << maxi;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
int s[26 + 5], c[26 + 5];

bool ist(int k)
{
	for (int i = 0; i < 31; i++)
	{
		s[i] = 0;
		c[i] = 0;
	}
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (a[j] >= 'a' && a[j] <= 'z')
				s[a[j] - 'a']++;
			else
				c[a[j] = 'A']++;
		}
	}
	for (int i = 0; i < 31; i++)
	{
		if (s[i] >= a.size() - k + 1 || c[i] >= a.size() - k + 1)
			return true;
	}
	return false;
}

int main()
{
	cin >> a;
	int s = -1, l = 53, m = 0;
	if(a.size() < 53)
		l = a.size();
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <set>
using namespace std;
string a;
set<char> pos;
set<char> pos2;

bool ist(int k)
{
	pos.clear();
	pos2.clear();
	int i;
	for (i = 0; i + k - 1 < a.size(); i++)
	{
		for (int j = i; j < i + k; j++)
		{
			if (i == 0)
				pos.insert(a[j]);
			else
			{
				if (i % 2 == 1)
				{
					if (pos.find(a[j]) != pos.end())
						pos2.insert(a[j]);
				}
				else
				{
					if (pos2.find(a[j]) != pos2.end())
						pos.insert(a[j]);
				}
			}
		}
		if (i % 2 == 1)
			pos.clear();
		else
			pos2.clear();
	}
	if (i % 2 == 0)
	{
		if (pos2.size() >= 1)
			return true;
		else
			return false;
	}
	else
	{
		if (pos.size() >= 1)
			return true;
		else
			return false;
	}
}

int main()
{
	cin >> a;
	int s = -1, l = a.size() + 1, m = 0;
	while (s + 1 != l)
	{
		m = (s + l) / 2;
		if (ist(m))
			l = m;
		else
			s = m;
	}
	cout << l;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int maxi = 1e7, mt;
string a;
vector<int> s[26];

int main()
{
	ios::sync_with_stdio(false);
	cin >> a;
	for (int i = 0; i < 26; i++)
		s[i].push_back(-1);

	for (int i = 0; i < a.size(); i++)
	{
			s[a[i] - 'a'].push_back(i);
	}

	for (int i = 0; i < 26; i++)
	{
		mt = 0;
		if (s[i].size() > 1)
			s[i].push_back(a.size());
		for (int j = 1; j < s[i].size(); j++)
		{
			mt = max(mt, s[i][j] - s[i][j - 1]);
			if (mt > maxi)
				break;
		}
		if (mt > 0)
			maxi = min(mt, maxi);
		if (maxi == 1)
			break;
	}
	if (maxi == 1e7)
		cout << a.size();
	else
		cout << maxi;
}


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

#define rep(i, a, b)    for (int i = a; i < b; i++)
#define per(i, a, b)    for (int i = a; i >= b; i--)
#define ll              long long
#define ld              long double
#define all(x)          (x).begin(), (x).end()
#define pb              push_back

int main() {
	string s;
	cin >> s;
	vector<int> a[26];
	rep (i, 0, s.length())
		a[s[i] - 'a'].pb(i);
	int ans = s.length() / 2 + 1;
	rep (i, 0, 26) {
		if (a[i].size() < 2)
			continue;
		int m = 0;
		rep (j, 0, a[i].size() - 1)
			m = max (m, a[i][j + 1] - a[i][j]);
		ans = min (ans, m);
	}
	cout << ans;
    return 0;
}


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

#define rep(i, a, b)    for (int i = a; i < b; i++)
#define per(i, a, b)    for (int i = a; i >= b; i--)
#define ll              long long
#define ld              long double
#define all(x)          (x).begin(), (x).end()
#define pb              push_back

int main() {
	string s;
	cin >> s;
	vector<int> a[26];
	rep (i, 0, 26)
	    a[i].pb(-1);
	rep (i, 0, s.length())
		a[s[i] - 'a'].pb(i);
	rep (i, 0, 26)
	    a[i].pb(s.length());
	int ans = s.length() / 2 + 1;
	rep (i, 0, 26) {
		if (a[i].size() < 4)
			continue;
		int m = 0;
		rep (j, 0, a[i].size() - 1)
			m = max (m, a[i][j + 1] - a[i][j]);
		ans = min (ans, m);
	}
	cout << ans;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
	int i, j, l, r, m = 1, len = 0, a[26], b[26], k;
	string s;
	cin >> s;
	while (static_cast<int>(s[len]) != 0)
		len++;
	l = 0;
	r = len - 1;
	while (l < r) {
		m = (l + r) / 2;
		k = 0;
		for (i = 0; i < 26; i++)
			b[i] = 1;
		for (i = 0; i < len - m; i++) {
			for (j = 0; j < 26; j++)
				a[j] = 0;
			for (j = i; j < i + m; j++)
				a[static_cast<int>(s[j]) - 97] = 1;
			for (j = 0; j < 26; j++)
				if (a[j] == 0)
					b[j] = 0;
		}
		for (i = 0; i < 26; i++)
			if (b[i] == 1) {
				k++;
				break;
			}
		if (k == 0)
			l = m + 1;
		else
			r = m - 1;
	}
	cout << m;
	return 0;
}


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

#define rep(i, a, b)    for (int i = a; i < b; i++)
#define per(i, a, b)    for (int i = a; i >= b; i--)
#define ll              long long
#define ld              long double
#define all(x)          (x).begin(), (x).end()
#define pb              push_back

int main() {
	string s;
	cin >> s;
	vector<int> a[26];
	rep (i, 0, s.length())
		a[s[i] - 'a'].pb(i);
	int ans = s.length() / 2 + s.length() % 2;
	rep (i, 0, 26) {
		if (a[i].size() < 2)
			continue;
		int m = 0;
		rep (j, 0, a[i].size() - 1)
			m = max (m, a[i][j + 1] - a[i][j]);
		ans = min (ans, m);
	}
	cout << ans;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
	int i, j, l, r, m = 1, len = 0, a[26], b[26], k;
	string s;
	cin >> s;
	while (static_cast<int>(s[len]) != 0)
		len++;
	l = 0;
	r = len - 1;
	while (l <= r) {
		m = (l + r) / 2;
		k = 0;
		for (i = 0; i < 26; i++)
			b[i] = 1;
		for (i = 0; i <= len - m; i++) {
			for (j = 0; j < 26; j++)
				a[j] = 0;
			for (j = i; j < i + m; j++)
				a[static_cast<int>(s[j]) - 97] = 1;
			for (j = 0; j < 26; j++)
				if (a[j] == 0)
					b[j] = 0;
		}
		for (i = 0; i < 26; i++)
			if (b[i] == 1) {
				k++;
				break;
			}
		if (k == 0)
			l = m + 1;
		else
			r = m - 1;
	}
	cout << m;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
	int i, j, l, r, m = 1, len = 0, a[26], b[26], k;
	string s;
	cin >> s;
	while (static_cast<int>(s[len]) != 0)
		len++;
	l = 0;
	r = len - 1;
	while (l <= r) {
		m = (l + r) / 2;
		k = 0;
		for (i = 0; i < 26; i++)
			b[i] = 1;
		for (i = 0; i <= len - m; i++) {
			for (j = i; j < i + m; j++)
				a[static_cast<int>(s[j]) - 97] = 1;
			for (j = 0; j < 26; j++) {
				if (a[j] == 0)
					b[j] = 0;
				else
					a[j] = 0;
			}
		}
		for (i = 0; i < 26; i++)
			if (b[i] == 1) {
				k++;
				break;
			}
		if (k == 0)
			l = m + 1;
		else
			r = m - 1;
	}
	cout << m;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    int rec[26] = {-1};
    int m[26] = {-1};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }
    int len = s.size();
    for(int i=0;i<26;i++){
        m[i] = max(m[i],len-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    int rec[26] = {-1};
    int m[26] = {0};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }
    int len = s.size();
    for(int i=0;i<26;i++){
        m[i] = max(m[i],len-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    long rec[26] = {-1};
    long m[26] = {0};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }

    for(int i=0;i<26;i++){
        m[i] = max(m[i],s.size()-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    int m[26];
    int rec[26];
    for(int i=0;i<26;i++){
        rec[i] = m[i] = -1;
    }

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }
    int len = s.size();
    for(int i=0;i<26;i++){
        m[i] = max(m[i],len-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    int rec[26] = {-1};
    int m[26] = {0};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }

    for(int i=0;i<26;i++){
        m[i] = max(m[i],s.size()-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    int rec[26] = {-1};
    int m[26] = {0};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }
    int len = s.size();
    for(int i=0;i<26;i++){
        m[i] = max(m[i],s.len-rec[i]);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;

    int rec[26] = {-1};
    int m[26] = {0};

    for(int i=0;i<s.size();i++){
        int p = s[i]-'a';
        m[p] = max(m[p],i-rec[p]);
        rec[p] = i;
    }
    int len = s.size();
    for(int i=0;i<26;i++){
        m[i] = max(m[i],len-rec[i]+1);
    }

    int res = INT_MAX;
    for(int i=0;i<26;i++)
        if(m[i]<res)
            res = m[i];

    cout << res;
    return 0;
}


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
    lli b[26];
    mset(b);
    x=1;
    y=0;
    for(i=0;s[i];i++)
    {
    b[s[i]-'a']++;
    }
    for(i=0;i<26;i++)
    {
        if(b[i]>x)
        {
            x=b[i];
            y=i;
        }
    }
    k=(s.length()/2) + 1;

    if(x==1)
    {
        cout<<k;
        return 0;
    }
    vector <lli> v;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[y])
                v.pb(j);
        }
        x=v[1]-v[0];
        n=s.length();
        for(j=0;j<v.size()-1;j++)
            {
                x=max(x,v[j+1]-v[j]);
            }//abcdeb

        k=min(k,x);
    y=max(v[0]-0,n-v[v.size()-1]);
    k=max(y,k);
    cout<<k<<'\n';
}
// n=6
//aaaadd


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
vector <lli> v[26];
    for(i=0;i<26;i++)
    {
        x=1;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[i])
                v[i].pb(j);
        }
    }
    k=(s.length()/2) + 1;
    for(i=0;i<26;i++)
    {

        x=(s.length()/2) + 1;
        if(v[i].size()>1)
        {

        x=v[i][1]-v[i][0];
        for(j=0;j<v[i].size()-1;j++)
            {
                x=max(x,v[i][j+1]-v[i][j]);
            }

        }
        k=min(k,x);
    }
    cout<<k<<'\n';

}


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
vector <lli> v[26];
    for(i=0;i<26;i++)
    {
        x=1;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[i])
                v[i].pb(j);
        }
    }
    k=(s.length()/2) + 1;
    n=s.length();
    for(i=0;i<26;i++)
    {
        x=(s.length()/2) + 1;
        if(v[i].size()>1)
        {
        x=v[i][1]-v[i][0];
        for(j=0;j<v[i].size()-1;j++)
            {
             x=max(x,v[i][j+1]-v[i][j]);
            }
        x=max(x,max(v[i][0]-0+1,n-v[i][v[i].size()-1]));
        k=min(x,k);
        }
    }
    cout<<k<<'\n';

}


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
    lli b[26];
    mset(b);
    x=1;
    y=0;
    for(i=0;s[i];i++)
    {
    b[s[i]-'a']++;
    }
    for(i=0;i<26;i++)
    {
        if(b[i]>x)
        {
            x=b[i];
            y=i;
        }
    }
    k=(s.length()/2) + 1;

    if(x==1)
    {
        cout<<k;
        return 0;
    }
    vector <lli> v;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[y])
                v.pb(j);
        }
        x=v[1]-v[0]-1;
        n=s.length();
        for(j=0;j<v.size()-1;j++)
            {
                x=max(x,v[j+1]-v[j]);
            }//abcdeb

        k=min(k,x);
    y=max(v[0]-0,n-v[v.size()-1]);
    k=max(y,k);
    cout<<k<<'\n';

}
// n=6
//aaaadd


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
vector <lli> v[26];
    for(i=0;i<26;i++)
    {
        x=1;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[i])
                v[i].pb(j);
        }
    }
    k=(s.length()/2) + 1;
    n=s.length();
    for(i=0;i<26;i++)
    {

        x=(s.length()/2) + 1;
        if(v[i].size()>1)
        {
        x=v[i][1]-v[i][0];
        for(j=0;j<v[i].size()-1;j++)
            {
                x=max(x,v[i][j+1]-v[i][j]);
            }
        k=min(k,x);
        x=max(v[i][0]-0,n-v[i][v[i].size()-1]);
        k=max(x,k);
        }

    }
    cout<<k<<'\n';

}


#define lli long long int
#include <bits/stdc++.h>
#define arr(a,n) lli a[n]; for(i=0;i<n;i++){ cin>>a[i]; }
#define ma(a,n) *max_element(a,a+n);
#define mi(a,n) *min_element(a,a+n);
#define br cout<<"\n";
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(v) v.begin(),v.end()
#define mset(a) memset(a,0,sizeof a);
#define mod 1000000007
using namespace std;
int main()
{	ios::sync_with_stdio(false);
	lli i,j,k,y,l,r,m,n,x,t;
    string s;
    cin>>s;
    char a[26];
    for(i=0;i<26;i++)
        a[i]='a'+i;//cout<<a[i]<<" ";

    k=99999999;
vector <lli> v[26];
    for(i=0;i<26;i++)
    {
        x=1;
        for(j=0;s[j];j++)
        {
            if(s[j]==a[i])
                v[i].pb(j);
        }
    }
    k=(s.length()/2) + 1;
    n=s.length();
    for(i=0;i<26;i++)
    {
        x=(s.length()/2) + 1;
        if(v[i].size()>1)
        {
        x=v[i][1]-v[i][0];
        for(j=0;j<v[i].size()-1;j++)
            {
             x=max(x,v[i][j+1]-v[i][j]);
            }
        k=min(k,x);// abbcs
        x=max(v[i][0]-0+1,n-v[i][v[i].size()-1]);
        k=max(x,k);
        }
    }
    cout<<k<<'\n';

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	 int x=n/2+1;
for(int j=0;j<26;j++){
     if(v[j].size()>1){

	int diff=0;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= max(diff, v[j][i]-v[j][i-1]);
	 }
	 diff = max(diff, (int)((int)s.length() - v[j][v[j].size() - 1]) );
       	 x=min(x,diff);
}
}
	 cout <<x <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	 int x=n/2+1;
for(int j=0;j<26;j++){
     if(v[j].size()>1){

	int diff=0;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= max(diff, v[j][i]-v[j][i-1]);
	 }
	 diff = max(diff, (int)((int)s.length() - v[j][v[j].size() - 1]) + 1);
       	 x=min(x,diff);
}
}
	 cout <<x <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	int diff=INT_MAX;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= min(diff, v[j][i]-v[j][i-1]);
	 }

	 cout <<diff <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	int diff=0;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= max(diff, v[j][i]-v[j][i-1]);
	 }

	 cout <<min(diff,n/2+1) <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;

     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){

     	v[s[i]-'a'].push_back(i);
	 }

	 int ans=n/2+1;

/*	 cout <<m<<" "<<j<<endl;*/
	 /*cout <<v[j].size();*/

 for(int i = 0; i < 26; i++)
   {
       int temp = 0;
       if(v[i].size() > 0) temp = v[i][0];
       for(int j = 1; j < v[i].size();j++)
       {
           temp = max(temp, v[i][j] - v[i][j-1]);
       }
       if(v[i].size() > 0)
       temp = max(temp, (int)((int)s.length() - v[i][v[i].size() - 1]) );
       if(temp == 0) temp = s.length();
       ans = min(ans, temp);
}
	 cout <<ans <<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	 int x=n/2+1;
for(int j=0;j<26;j++){
     if(v[j].size()>1){

	int diff=0;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= max(diff, v[j][i]-v[j][i-1]);
	 }
	 x=min(x,diff);
}
}
	 cout <<x <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

vector<int> v[30];
int main()
{
   int ans=0;
   string s;
   cin >> s;
   ans = ((s.length())/2) + 1;
   for(int i = 0; i < s.length(); i++)
   {
        v[s[i]-'a'].pb(i + 1);
   }

   for(int i = 0; i < 26; i++)
   {
       int temp = 0;
       if(v[i].size() > 0) temp = v[i][0];
       for(int j = 1; j < v[i].size();j++)
       {
           temp = max(temp, v[i][j] - v[i][j-1]);
       }
       if(v[i].size() > 0)
       temp = max(temp, (int)((int)s.length() - v[i][v[i].size() - 1]) + 1);
       if(temp == 0) temp = s.length();
       ans = min(ans, temp);
   }
   cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
     string s;
     cin>>s;
     int a[26]={0};
     vector<int>v[26];
     int n=s.length();
     for(int i=0;i<n;i++){
     	a[s[i]-'a']++;
     	v[s[i]-'a'].push_back(i);
	 }
	 int m=0,j;
	 for(int i=0;i<26;i++)
     {
     /*	cout <<a[i]<<" ";*/
       if(a[i]>m){
       	m=a[i];
       	j=i;
	   }
	 }
/*	 cout <<m<<" "<<j<<endl;*/
	 if(m!=1){
	 /*cout <<v[j].size();*/
	int diff=0;
for(int i =v[j].size()-1;i>=1;i--){
	 diff= max(diff, v[j][i]-v[j][i-1]);
	 }

	 cout <<diff <<endl;

  }

  else if(m==1&&n==1) cout <<1<<endl;

  else{
  	int mid=n/2+1;
  	cout <<mid<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    vector<ll>v[26];
    vector<ll>::iterator it;
    vector<ll>::iterator it1;
    for(ll i=0;i<26;i++)
    {
        v[i].push_back(0);
    }
    for(ll i=0;i<s.size();i++)
    {
        v[s[i]-'a'].push_back(i);
    }
    for(ll i=0;i<26;i++)
    {
        if((i)!=(s[s.size()-1]-'a'))
        v[i].push_back(s.size());
    }
    ll maxi=(s.size()+2)/2;
    ll mini[26];
    for(ll i=0;i<26;i++)
        mini[i]=INT_MAX;
        ll chk=s[s.size()-1]-'a';
    for(ll i=0;i<26;i++)
    {
         ll diff=INT_MIN;
        if((i==chk && v[i].size()>2)|| (v[i].size()>3))
        {
            it1=v[i].begin();
            it1++;
            for(it=v[i].begin();it!=v[i].end() && it1!=v[i].end();it++)
            {
                    diff=max(diff,*it1-*it);
                    it1++;
            }
        }
        if(diff!=INT_MIN)
        mini[i]=diff;
    }
    sort(mini,mini+26);
    cout<<min(mini[0],maxi);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[26];
vector<int>::iterator it;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<s.size();i++)
    {
       v[s[i]-'a'].push_back(i);
    }
    int ans=INT_MAX;
    for(int i=0;i<26;i++)
    {
        int here=0;
        if(v[i].size()==0)
        {
            continue;
        }
        else if(v[i].size()==1)
        {
            int one=*v[i].begin()+1;
            int two=s.size()-*v[i].begin();
            here=max(one,two);
        }
        else
        {
            here=*v[i].begin()+1;
            int prev=*v[i].begin();
            it=v[i].begin();
            it++;
            while(it!=v[i].end())
            {
                here=max(here,*it-prev);
                prev=*it;
                it++;
            }
            it--;
            here=max(here,(n-*it));
        }
        ans=min(ans,here);
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    vector<ll>v[26];
    vector<ll>::iterator it;
    vector<ll>::iterator it1;
    for(ll i=0;i<s.size();i++)
    {
        v[s[i]-'a'].push_back(i);
    }
    ll maxi=(s.size()+1)/2;
    ll mini[26];
    for(ll i=0;i<26;i++)
        mini[i]=INT_MAX;
    for(ll i=0;i<26;i++)
    {
         ll diff=INT_MIN;
        if(v[i].size()>1)
        {
            it1=v[i].begin();
            it1++;
            for(it=v[i].begin();it!=v[i].end() && it1!=v[i].end();it++)
            {
                    diff=max(diff,*it1-*it);
                    it1++;
            }
        }
        if(diff!=INT_MIN)
        mini[i]=diff;
    }
    sort(mini,mini+26);
    cout<<min(mini[0],maxi);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    vector<ll>v[26];
    vector<ll>::iterator it;
    vector<ll>::iterator it1;
    for(ll i=0;i<26;i++)
    {
        v[i].push_back(-1);
    }
    for(ll i=0;i<s.size();i++)
    {
        v[s[i]-'a'].push_back(i);
    }
    for(ll i=0;i<26;i++)
    {
        if((i)!=(s[s.size()-1]-'a'))
        v[i].push_back(s.size());
    }
    ll maxi=(s.size()+2)/2;
    ll mini[26];
    for(ll i=0;i<26;i++)
        mini[i]=INT_MAX;
        ll chk=s[s.size()-1]-'a';
    for(ll i=0;i<26;i++)
    {
         ll diff=INT_MIN;
        if((i==chk && v[i].size()>2)|| (v[i].size()>3))
        {
            it1=v[i].begin();
            it1++;
            for(it=v[i].begin();it!=v[i].end() && it1!=v[i].end();it++)
            {
                    diff=max(diff,*it1-*it);
                    it1++;
            }
        }
        if(diff!=INT_MIN)
        mini[i]=diff;
    }
    sort(mini,mini+26);
    cout<<min(mini[0],maxi);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>v[26];
vector<int>::iterator it;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
       v[s[i]-'a'].push_back(i);
    }
    int ans=INT_MAX;
    for(int i=0;i<26;i++)
    {
        int here=0;
        if(v[i].size()==0)
        {
            continue;
        }
        else if(v[i].size()==1)
        {
            int one=i-0+1;
            int two=s.size()-i;
            here=max(one,two);
        }
        else
        {
            int prev=*v[i].begin();
            it=v[i].begin();
            it++;
            while(it!=v[i].end())
            {
                here=max(here,*it-prev);
                prev=*it;
                it++;
            }
        }
        ans=min(ans,here);
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    vector<ll>v[26];
    vector<ll>::iterator it;
    vector<ll>::iterator it1;
    for(ll i=0;i<s.size();i++)
    {
        v[s[i]-'a'].push_back(i);
    }
    ll maxi=(s.size()+2)/2;
    ll mini[26];
    for(ll i=0;i<26;i++)
        mini[i]=INT_MAX;
    for(ll i=0;i<26;i++)
    {
         ll diff=INT_MIN;
        if(v[i].size()>1)
        {
            it1=v[i].begin();
            it1++;
            for(it=v[i].begin();it!=v[i].end() && it1!=v[i].end();it++)
            {
                    diff=max(diff,*it1-*it);
                    it1++;
            }
        }
        if(diff!=INT_MIN)
        mini[i]=diff;
    }
    sort(mini,mini+26);
    cout<<min(mini[0],maxi);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){x=j;m=0;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(x!=-1 && n-x+1>m && s[n-1]!=s[x])m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){if(n%2==0)if(j+1>n/2){break;}if(n%2!=0)if(j+1>n-n/2){break;}x=j;m=0;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(x!=-1 && n-x+1>m && s[n-1]!=s[x])m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{if(n%2==0){if(b[l]>n/2+1)continue;}else if(b[l]>n-n/2)continue;cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){if(n%2==0)if(j+1>n/2){break;}if(n%2!=0)if(j+1>n-n/2){break;}x=j;m=0;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(n-x+1>m && s[n-1]!=s[x])m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{if(n%2==0){if(b[l]>n/2+1)continue;}else if(b[l]>n-n/2)continue;cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){if(n%2==0)if(j+1>n/2){break;}if(n%2!=0)if(j+1>n-n/2){break;}x=j;m=j+1;}
                else {if(j-x>=m)m=j-x;x=j;}
            }
        }
        if(n-x>m && s[n-1]!=s[x])m=n-x;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{if(n%2==0){if(b[l]>n/2+1)continue;}else if(b[l]>n-n/2)continue;cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){x=j;m=j;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{ cout<<b[l];g=1;break;}
    }
    if(g==0)cout<<"0";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){if(j>n/2){continue;}x=j;m=0;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(x!=-1 && n-x+1>m && s[n-1]!=s[x])m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{if(n%2==0){if(b[l]>n/2+1)continue;}else if(b[l]>n-n/2)continue;cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){if(n%2==0)if(j+1>n/2){break;}if(n%2!=0)if(j+1>n-n/2){break;}x=j;m=j+1;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(x!=-1 && n-x+1>m && s[n-1]!=s[x])m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{if(n%2==0){if(b[l]>n/2+1)continue;}else if(b[l]>n-n/2)continue;cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    bool a[26]={}; int b[26]={};
    for(int i=0;i<n;i++){
        a[s[i]-'a']=1;
    }
    int i=0,k=0;
    while(i<=25){
        if(a[i]==0){i++;continue;}
        int x=-1,m;
        for(int j=0;j<n;j++){
            if(s[j]==('a'+i)){
                if(x==-1){x=j;m=0;}
                else {if(j-x>m)m=j-x;x=j;}
            }
        }
        if(x!=-1 && n-x+1>m)m=n-x+1;
        i++;
        b[k++]=m;
    }
    bool g=0;
    sort(b,b+26);
    for(int l=0;l<26;l++){
        if(b[l]==0)continue;
        else{cout<<b[l];g=1;break;}
    }
    if(g==0){if(n%2==0)cout<<n/2+1;else cout<<n-n/2;}
    return 0;
}