#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

n,m,o=value()
a=[]
for i in range(n):
    a.append(array())

ans=[]
for i in range(1,m+1):
    for j in range(1,m+1):

        ok=False
        for k in range(n):
            if(a[k][i-1]>a[k][j-1]):
                ok=True
        if(ok and (j,i) not in ans):
            ans.append((i,j))

print(len(ans))
for i in ans:
    print(*i)


#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

n,m,_=value()
for i in range(n):
    input()

print(m*(m+1)//2)
for i in range(1,m+1):
    for j in range(i+1,m+1):
        print(i,j)


#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=1000000007
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
# vsInput()

n,m,_=value()
for i in range(n):
    input()

print(m*(m-1)//2)
for i in range(1,m+1):
    for j in range(i+1,m+1):
        print(i,j)


n,m,k = map(int,input().split())
for i in range(n):
    li = list(map(int,input().split()))
ans=[]
for i in range(1,m+1):
    for j in range(i+1,m+1):
        ans.append([i,j])
if k==0:
    print(len(ans))
    for i in ans:
        print(*i)
else:
    print(len(ans))
    for i in ans[::-1]:
        print(*i[::-1])


def arr_inp(n):
    if n == 1:
        return [int(x) for x in stdin.readline().split()]
    elif n == 2:
        return [float(x) for x in stdin.readline().split()]
    else:
        return [str(x) for x in stdin.readline().split()]

from sys import stdin
from itertools import *

n, m, k = arr_inp(1)
arr, ans = [arr_inp(1) for i in range(n)], list(combinations(range(1, m + 1), 2))
print(len(ans))
for i in range(len(ans)):
    if k:
        print(ans[i][1], ans[i][0])
    else:
        print(ans[i][0], ans[i][1])


# ls.sort(key=lambda x: (x[0], x[1]))
import sys

inf = float("inf")
mod = 1000000007

def array(): return list(map(int, sys.stdin.readline().split()))
def intt(): return map(int, sys.stdin.readline().split())
from bisect import bisect_left
import sys
#n, k = map(int, sys.stdin.readline().split())
#arr = list(map(int, sys.stdin.readline().split()))
#arr=[(int(x),i) for i,x in enumerate(input().split())]
# ls=list(map(int,input().split()))
# for i in range(m):
#print(s[i],end="")
#n=int(sys.stdin.readline())
n,m,k=map(int, sys.stdin.readline().split())
ls=[]
for i in range(n):
    arr = list(map(int, sys.stdin.readline().split()))
    ls.append(arr)
print(m*(m-1)//2)
for i in range(1,m):
    for j in range(i+1,m+1):
        if k==0:
            print(i, j)
        else:
            print(j, i)


//本质上是输出包含左右字符种类的最短字符串
//the code is not written by myself
#include<iostream>
#include<string>
using namespace std;
string s;
int n, res, cou[100];
int main()
{
	cin >> n >> s;
	int left = 0;//left表示左边起始位置
	for (int i = 0; i <n; ++i)
	{
		if (cou[s[i] - 'A'] == 0)
			res = i - left + 1;
		cou[s[i] - 'A']++;
		while (left<i)
		{
			if (cou[s[left] - 'A']>1)
			{
				cou[s[left] - 'A']--;
				left++;
			}
			else break;
		}
		if (res>i - left + 1)
			res = i - left + 1;
	}
	cout << res << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main()
{
	string s;
	set <char> a,b;

	map <char, int> mm;
	int f, ll,mi=99999999;

	long long n,l;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a.insert(s[i]);
	l = a.size();
	f = 0; ll = 0;
	for (int i = 0; i < n,b.size()<l; i++)
	{
		ll++;
		b.insert(s[i]);
		mm[s[i]]++;

	}
	mi = min(mi,ll - f);
	while (f<n)
	{
		bool k = false;
		while ( f<ll)
		{
			if (mm[s[f]]>1 )
			{
				mm[s[f]]--;
				f++;
			}
			else
			{
				k = true;
				break;
			}

		}
		if (k)
		{
			mi = min(mi, ll - f);
			mm[s[f]]--;
			f++;
		}
		else
			break;

		bool  m = false;
		while ( ll<n+1)
		{
			if (s[ll - 1] != s[f - 1])
				ll++;
			else
			{
				m = true;
				break;
			}

		}

		if (mm[s[ll - 1]] == mm[s[f - 1]] && m)
		{

			mm[s[ll-1]]++;
			mi = min(mi, ll - f);

		}
		if ((ll == n && mm[s[f]] == 0) || !m)
			break;

	}
	if (mi <b.size())
		mi=b.size();
	cout << mi << endl;
	//cin >> mi;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main()
{
	string s;
	set <char> a,b;

	map <char, int> mm;
	int f, ll,mi=99999999;

	long long n,l;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a.insert(s[i]);
	l = a.size();
	f = 0; ll = 0;
	for (int i = 0; i < n,b.size()<l; i++)
	{
		ll++;
		b.insert(s[i]);
		mm[s[i]]++;

	}
	mi = min(mi,ll - f);
	while (f<n)
	{
		bool k = false;
		while ( f<ll)
		{
			if (mm[s[f]]>1 )
			{
				mm[s[f]]--;
				f++;
			}
			else
			{
				k = true;
				break;
			}

		}
		if (k)
		{
			mi = min(mi, ll - f);
			mm[s[f]]--;
			f++;
		}
		else
			break;

		bool  m = false;
		while ( ll<n)
		{
			if (s[ll - 1] != s[f - 1])
				ll++;
			else
			{
				m = true;
				break;
			}

		}

		if (mm[s[ll - 1]] == mm[s[f - 1]] && m)
		{

			mm[s[ll]]++;
			mi = min(mi, ll - f);
		}
		if ((ll == n && mm[s[f]] == 0) || !m)
			break;

	}
	cout << mi << endl;
	//cin >> mi;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

using namespace std;

int main()
{

	vector <int> cc(300),ee(300);
	string see;

	int n;
	cin >> n;
	cin >> see;

	int  t = 0;
	for (int i = 0; i < n; i++)
	{
		t = t+ !ee[see[i]], ee[see[i]] = 1;
	}

	int c = 0;
	int minne = 1 << 30;
	for (int i = 0, j = 0; i < n; i++)
	{
		c += !cc[see[i]];
		cc[see[i]]++;
		if (c >= t)
		{
			minne = min(minne, i - j + 1);
		}

		while (c > t)
		{
			cc[see[j]]--;
			if (!cc[see[j]]) c--;
			{
				j++;
			}

		}

		if (c >= t)
		{
			while (cc[see[j]] > 1)
			{
				cc[see[j]]--, j++;
			}
			minne = min(minne, i - j + 1);
		}

	}
	cout << minne << endl;

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main()
{
	string s;
	set <char> a,b;

	map <char, int> mm;
	int f, ll,mi=99999999;

	long long n,l;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a.insert(s[i]);
	l = a.size();
	f = 0; ll = 0;
	for (int i = 0; i < n,b.size()<l; i++)
	{
		ll++;
		b.insert(s[i]);
		mm[s[i]]++;

	}
	mi = min(mi,ll - f);
	while (f<n)
	{
		bool k = false;
		while ( f<ll)
		{
			if (mm[s[f]]>1 )
			{
				mm[s[f]]--;
				f++;
			}
			else
			{
				k = true;
				break;
			}

		}
		if (k)
		{
			mi = min(mi, ll - f);
			mm[s[f]]--;
			f++;
		}
		else
			break;

		bool  m = false;
		while ( ll<n)
		{
			if (s[ll - 1] != s[f - 1])
				ll++;
			else
			{
				m = true;
				break;
			}

		}

		if (mm[s[ll - 1]] == mm[s[f - 1]] && m)
		{

			mm[s[ll]]++;
			mi = min(mi, ll - f);

		}
		if ((ll == n && mm[s[f]] == 0) || !m)
			break;

	}
	if (mi <b.size())
		mi=b.size();
	cout << mi << endl;
	//cin >> mi;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int main()
{
	string s;
	set <char> a,b;

	map <char, int> mm;
	int f, ll,mi=99999999;

	long long n,l;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a.insert(s[i]);
	l = a.size();
	f = 0; ll = 0;
	for (int i = 0; i < n,b.size()<l; i++)
	{
		ll++;
		b.insert(s[i]);
		mm[s[i]]++;

	}
	mi = min(mi,ll - f);
	while (f<n)
	{
		bool k = false;
		while ( f<ll)
		{
			if (mm[s[f]]>1 )
			{
				mm[s[f]]--;
				f++;
			}
			else
			{
				k = true;
				break;
			}

		}
		if (k)
		{
			mi = min(mi, ll - f);
			mm[s[f]]--;
			f++;
		}
		else
			break;

		bool  m = false;
		while ( ll<n)
		{
			if (s[ll - 1] != s[f - 1])
				ll++;
			else
			{
				m = true;
				break;
			}

		}

		if (mm[s[ll - 1]] == mm[s[f - 1]] && m)
		{

			mm[s[ll]]++;
			mi = min(mi, ll - f);

		}
		if ((ll == n && mm[s[f]] == 0) || !m)
			break;

	}
	if (mi == 0)
		mi++;
	cout << mi << endl;
	//cin >> mi;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <set>
#include <map>
#define MAX 110000
#define INF 1e8+7
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define mef(a) memset(a,0x3f,sizeof(a))
using namespace std;
#define LL long long
char s[MAX];
set<char>all;
map<char,int >mp;
int main()
{
    int n ;
     cin>>n;
    {
        scanf("%s",s);
        for(int i=0;i<n;i++)
            all.insert(s[i]);
        int m=all.size();
      //  cout<<m<<endl;

        int sum=0,i=0,l=0,ans=999999;

        while(1)
        {
            while(sum<m&&i<n)
            {
                if(mp[s[i]]==0)
                {
                    sum++;
                }
                 mp[s[i++]]++;
            }

          //  cout<<sum<<"  "<<i<<endl;
            if(sum<m) break;
            ans=min(ans,i-l);
            if(--mp[s[l++]]==0)
                sum--;
        }
            cout<<ans<<endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <set>
#include <map>
#define MAX 110000
#define INF 1e8+7
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define mef(a) memset(a,0x3f,sizeof(a))
using namespace std;
#define LL long long
char s[MAX];
set<char>all;
map<char,int >mp;
int main()
{
    int n ;
     cin>>n;
    {
        scanf("%s",s);
        for(int i=0;i<n;i++)
            all.insert(s[i]);
        int m=all.size();
        cout<<m<<endl;

        int sum=0,i=0,l=0,ans=99999;

        while(1)
        {
            while(sum<m&&i<n)
            {
                if(mp[s[i]]==0)
                {
                    sum++;
                }
                 mp[s[i++]]++;
            }

          //  cout<<sum<<"  "<<i<<endl;
            if(sum<m) break;
            ans=min(ans,i-l);
            if(--mp[s[l++]]==0)
                sum--;
        }
            cout<<ans<<endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <set>
#include <map>
#define MAX 110000
#define INF 1e8+7
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define mef(a) memset(a,0x3f,sizeof(a))
using namespace std;
#define LL long long
char s[MAX];
set<char>all;
map<char,int >mp;
int main()
{
    int n ;
     cin>>n;
    {
        scanf("%s",s);
        for(int i=0;i<n;i++)
            all.insert(s[i]);
        int m=all.size();
      //  cout<<m<<endl;

        int sum=0,i=0,l=0,ans=99999;

        while(1)
        {
            while(sum<m&&i<n)
            {
                if(mp[s[i]]==0)
                {
                    sum++;
                }
                 mp[s[i++]]++;
            }

          //  cout<<sum<<"  "<<i<<endl;
            if(sum<m) break;
            ans=min(ans,i-l);
            if(--mp[s[l++]]==0)
                sum--;
        }
            cout<<ans<<endl;
    }

    return 0;
}


//
//  main.cpp
//

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

using namespace std;

#define ll long long

ll temp;
ll n;
string s;
set <ll> letters[52];

ll count(int letter, ll rangeStart, ll rangeEnd) {
    if (letter > 49) {
        if (rangeStart == LLONG_MAX || rangeEnd == LLONG_MAX) {
            return LLONG_MAX;
        }
        else
            return rangeEnd - rangeStart + 1;
    }

    set <ll> possibleIndexes = letters[letter];

    if (possibleIndexes.size() == 0) {
        return count(letter + 1, rangeStart, rangeEnd);
    }

    if (rangeStart == -1 && rangeEnd == -1) {
        ll res = LLONG_MAX;
        for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
            res = min(res, count(letter + 1, *it, *it));
        }
        return res;
    }

    ll firstBeforeRange = -1;
    ll firstAfterRange = LLONG_MAX;
    for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
        if (*it >= rangeStart && *it <= rangeEnd) {
            return count(letter + 1, rangeStart, rangeEnd);
        }
        else if (*it < rangeStart && *it > firstBeforeRange) {
            firstBeforeRange = *it;
        }
        else if (*it > rangeEnd && *it < firstAfterRange) {
            firstAfterRange = *it;
        }
    }

    if (firstBeforeRange != -1 && firstAfterRange != LLONG_MAX) {
        return min(count(letter + 1, firstBeforeRange, rangeEnd), count(letter + 1, rangeStart, firstAfterRange));
    }
    else if (firstBeforeRange != -1)
        return count(letter + 1, firstBeforeRange, rangeEnd);
    else if (firstAfterRange != LLONG_MAX)
        return count(letter + 1, rangeStart, firstAfterRange);

    return 0;
}

int main(int argc, const char * argv[]) {
    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++) {
        char ch = s[i];
        int index = ch >= 'a' ? ch - 'a' + 'Z' - 'A' + 1 : ch - 'A';
        letters[index].insert(i);
    }

    cout << count(0, -1, -1);

    return 0;
}


//
//  main.cpp
//

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

using namespace std;

#define ll long long

ll temp;
ll n;
string s;
set <ll> letters[52];

ll count(int letter, ll rangeStart, ll rangeEnd) {
    if (letter > 51) {
        if (rangeStart == LLONG_MAX || rangeEnd == LLONG_MAX) {
            return LLONG_MAX;
        }
        else
            return rangeEnd - rangeStart + 1;
    }

    set <ll> possibleIndexes = letters[letter];

    if (possibleIndexes.size() == 0) {
        return count(letter + 1, rangeStart, rangeEnd);
    }

    if (rangeStart == -1 && rangeEnd == -1) {
        ll res = LLONG_MAX;
        for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
            res = min(res, count(letter + 1, *it, *it));
        }
        return res;
    }

    ll firstBeforeRange = -1;
    ll firstAfterRange = LLONG_MAX;
    for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
        if (*it >= rangeStart && *it <= rangeEnd) {
            return count(letter + 1, rangeStart, rangeEnd);
        }
        else if (*it < rangeStart && *it > firstBeforeRange) {
            firstBeforeRange = *it;
        }
        else if (*it > rangeEnd && *it < firstAfterRange) {
            firstAfterRange = *it;
        }
    }

    if (firstBeforeRange != -1 && firstAfterRange != LLONG_MAX) {
        return min(count(letter + 1, firstBeforeRange, rangeEnd), count(letter + 1, rangeStart, firstAfterRange));
    }
    else if (firstBeforeRange != -1)
        return count(letter + 1, firstBeforeRange, rangeEnd);
    else if (firstAfterRange != LLONG_MAX)
        return count(letter + 1, rangeStart, firstAfterRange);

    return 0;
}

int main(int argc, const char * argv[]) {
    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++) {
        char ch = s[i];
        int index = ch >= 'a' ? ch - 'a' + 'Z' - 'A' + 1 : ch - 'A';
        letters[index].insert(i);
    }

    cout << count(0, -1, -1);

    return 0;
}


//
//  main.cpp
//

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

using namespace std;

#define ll long long

ll temp;
ll n;
string s;
set <ll> letters[50];

ll count(int letter, ll rangeStart, ll rangeEnd) {
    if (letter > 49) {
        if (rangeStart == LLONG_MAX || rangeEnd == LLONG_MAX) {
            return LLONG_MAX;
        }
        else
            return rangeEnd - rangeStart + 1;
    }

    set <ll> possibleIndexes = letters[letter];

    if (possibleIndexes.size() == 0) {
        return count(letter + 1, rangeStart, rangeEnd);
    }

    if (rangeStart == -1 && rangeEnd == -1) {
        ll res = LLONG_MAX;
        for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
            res = min(res, count(letter + 1, *it, *it));
        }
        return res;
    }

    ll firstBeforeRange = -1;
    ll firstAfterRange = LLONG_MAX;
    for (std::set<ll>::iterator it=possibleIndexes.begin(); it!=possibleIndexes.end(); ++it) {
        if (*it >= rangeStart && *it <= rangeEnd) {
            return count(letter + 1, rangeStart, rangeEnd);
        }
        else if (*it < rangeStart && *it > firstBeforeRange) {
            firstBeforeRange = *it;
        }
        else if (*it > rangeEnd && *it < firstAfterRange) {
            firstAfterRange = *it;
        }
    }

    if (firstBeforeRange != -1 && firstAfterRange != LLONG_MAX) {
        return min(count(letter + 1, firstBeforeRange, rangeEnd), count(letter + 1, rangeStart, firstAfterRange));
    }
    else if (firstBeforeRange != -1)
        return count(letter + 1, firstBeforeRange, rangeEnd);
    else if (firstAfterRange != LLONG_MAX)
        return count(letter + 1, rangeStart, firstAfterRange);

    return 0;
}

int main(int argc, const char * argv[]) {
    cin >> n;
    cin >> s;

    for (int i = 0; i < n; i++) {
        char ch = s[i];
        int index = ch >= 'a' ? ch - 'a' + 'Z' - 'A' + 1 : ch - 'A';
        letters[index].insert(i);
    }

    cout << count(0, -1, -1);

    return 0;
}


//
//  main.cpp
//

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

using namespace std;

#define ll long long

ll temp;
ll n;
string s;
set <ll> letters[52];

ll arr[1000000];

vector <ll> lastEntry;

int convertChar(char ch) {
    return ch >= 'a' ? ch - 'a' + 'Z' - 'A' + 1 : ch - 'A';
}

void setArrI(int index) {
    ll leftBound = LLONG_MAX;
    for (int i = 0; i < 52; i++) {
        if (letters[i].size() > 0) {
            if (lastEntry[i] == -1) {
                leftBound = LLONG_MAX;
                break;
            }
            else {
                leftBound = min(leftBound, lastEntry[i]);
            }
        }
    }

    arr[index] = leftBound == LLONG_MAX ? LLONG_MAX : index - leftBound + 1;
}

int main(int argc, const char * argv[]) {
    cin >> n;
    cin >> s;

    for (int i = 0; i < 52; i++) {
        lastEntry.push_back(-1);
    }

    for (int i = 0; i < n; i++) {
        char ch = s[i];
        int index = convertChar(ch);
        letters[index].insert(i);
    }

    for (int i = 0; i < n; i++) {
        char ch = s[i];
        int index = convertChar(ch);
        lastEntry[index] = i;
        setArrI(i);
    }

    ll result = n;
    for (int i = 0; i < n; i++) {
        result = min(result, arr[i]);
    }

    cout << result;

    return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <algorithm>

//#pragma comment(linker, "/STACK:166777216")

using namespace std;

int main()
{
	int n, a[300] = { 0 }, b[300] = {0}, i, cnt, l, r, k, min;
	char s[100005];

	scanf("%d\n%s", &n, s);

	for (i = 0; i < n; i++)
		a[s[i]]++;

	cnt = 0;
	for (i = 0; i < 300; i++)
		if (a[i] > 0)
			cnt++;

	l = r = k = 0;
	min = n;
	while (r < n)
	{
		if (b[s[r]] == 0)
			k++;

		b[s[r]]++;

		if (k == cnt)
		{
			while (b[s[l]] > 1)
			{
				b[s[l]]--;
				l++;
			}

			if (r - l + 1 < min)
				min = r - l + 1;
		}

		r++;
	}

	printf("%d", min);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>
#include <string>
#include <cstring>
#include <fstream>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
int main(){
	map<char, bool>m;
	string s;
	int n, i, minLen = INT_MAX;
	cin >>n>>s;
	set<char>st;
	for (int i = 0; i < n; i++)
		st.insert(s[i]);
	for (int i = 0; i < n; i++){
		int cnt = 0;
		for (char c = 'a'; c <= 'z'; c++)
			m[c] = false;
		for (char c = 'A'; c <= 'Z'; c++)
			m[c] = false;
		for (int j = i; j < n; j++){
			if (!m[s[j]]){
				m[s[j]] = true;
				cnt++;
			}
			if (cnt == st.size()){
				minLen = min(minLen, j - i + 1);
				break;
			}
		}
	}
	cout << minLen << endl;
	//system("pause");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <climits>
#include <string>
#include <cstring>
#include <fstream>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int sz = 100001;
const ll INF = 1000000000;
ll answerLength[sz], numElems;
bool foundElem[256];
char letters[52];
int main(){
	string s; int n; char curElem; int last;
	cin >> n >> s;
	for (int i = 0; i < n; i++){
		if (!foundElem[s[i]]){
			letters[numElems++] = s[i];
			foundElem[s[i]] = true;
		}
	}
	for (int i = 0; i < numElems; i++){
		curElem = letters[i];
		last = -1;
		for (int j = 0; j < n; j++){
			if (s[j] == curElem) last = j;
			if (last == -1) answerLength[j] = INF;
			else
				answerLength[j] = max<ll>(answerLength[j], j - last + 1);
		}
	}
	ll ans=INF;
	for (int i = 0; i <n; i++)
		ans = min(ans, answerLength[i]);
	cout << ans << endl;
	//system("pause");
	return 0;
}


#pragma warning(disable:4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
char c[100010];
int m[100010];
int g[100010];
int main(){
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, i, k, l, r, mk,ans;
	scanf("%d", &n);
	gets(c);
	gets(c);
	mk = 0;
	for (i = 0; i < strlen(c); i++)
	{
		if (g[c[i]] == 0)
		{
			mk++;
			g[c[i]]++;
		}
	}

	k = 1;
	m[c[0]] = 1;
	r = 0;
	ans = n;
	for (l = 0; l < n-1; l++)
	{
		while (r < n - 1 && k < mk)
		{
			r++;
			m[c[r]] ++;
			if (m[c[r]] == 1) k++;
		}
		if (k == mk) ans = min(ans, r - l + 1);
		if (m[c[l]] == 1) k--;
		m[c[l]]--;

	}
	printf("%d", ans);

	return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector<char>flats;
int total;
bool valid(int sz){
    set<char>deff;
    vector<int>freq(300);
    for (int i=0; i<sz; i++) {
        deff.insert(flats[i]);
        freq[flats[i]]++;
    }
    if (deff.size()==total) {
        return true;
    }
    for (int i=sz; i<flats.size(); i++) {
        freq[flats[i-sz]]--;
        if (freq[flats[i-sz]]==0) {
            deff.erase(flats[i-sz]);
        }
        deff.insert(flats[i]);
        freq[flats[i]]++;
        if (deff.size()==total) {
            return true;
        }
    }
    return false;
}
int main()
{
    int sz;
    cin>>sz;
    flats.resize(sz);
    set<char>deff;
    for (int i=0; i<sz; i++) {
        cin>>flats[i];
        deff.insert(flats[i]);
    }
    total=(int)deff.size();
    int mn=1,mx=sz;
    while (mx-mn>1) {
        int md=(mn+mx)/2;
        if (valid(md)) {
            mx=md;
        }
        else{
            mn=md;
        }
    }
    if (valid(mn)) {
        cout<<mn<<endl;
    }
    else{
        cout<<mx<<endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector<char>flats;
int total;
bool valid(int sz){
    set<char>deff;
    vector<int>freq(300);
    for (int i=0; i<sz; i++) {
        deff.insert(flats[i]);
        freq[flats[i]]++;
    }
    if (deff.size()==total) {
        return true;
    }
    for (int i=sz; i<flats.size(); i++) {
        freq[flats[i-sz]]--;
        if (freq[flats[i-sz]]==0) {
            deff.erase(flats[i-sz]);
        }
        deff.insert(flats[i]);
        freq[flats[i]]++;
        if (deff.size()==total) {
            return true;
        }
    }
    return false;
}
int main()
{
    int sz;
    cin>>sz;
    flats.resize(sz);
    set<char>deff;
    for (int i=0; i<sz; i++) {
        cin>>flats[i];
        deff.insert(flats[i]);
    }
    total=(int)deff.size();
    int mn=0,mx=sz;
    while (mx-mn!=1) {
        int md=(mn+mx)/2;
        if (valid(md)) {
            mx=md;
        }
        else{
            mn=md;
        }
    }
    if (valid(mn)) {
        cout<<mn<<endl;
    }
    else{
        cout<<mx<<endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector<vector<int>>poses(300,vector<int>(0,0));
bool bs(char f,int l,int h){
    int mx=(int)poses[f].size()-1,mn=0;
    while (mx-mn>1) {
        int md=(mx+mn)/2;
        if (poses[f][md]>=l&&poses[f][md]<=h) {
            return true;
        }
        else if (poses[f][md]>h){
            mx=md;
        }
        else if (poses[f][md]<l){
            mn=md;
        }
    }
    if (poses[f][mn]>=l&&poses[f][mn] <=h) {
        return true;
    }
    if (poses[f][mx]>=l&&poses[f][mx]<=h) {
        return true;
    }
    return false;
}
int main()
{
    int sz;
    cin>>sz;
    vector<char>flats(sz);
    set<char>temp;
    for (int i=0; i<sz; i++) {
        cin>>flats[i];
        poses[flats[i]].push_back(i);
        temp.insert(flats[i]);
    }
    for (int i=0; i<300; i++) {
        sort(poses[i].begin(), poses[i].end());
    }
    int ans=1e9;
    vector<int>freq(300,0);
    set<char>dups;
    for (int e=0,s=0; e<sz; e++) {
        freq[flats[e]]++;
        dups.insert(flats[e]);
        while (bs(flats[s], s+1, e)) {
            freq[flats[s]]--;
            if (freq[flats[s]]==0) {
                dups.erase(flats[s]);
            }
            s++;
        }
        if (dups.size()==temp.size()) {
            ans=min(e-s+1,ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
using namespace std;
vector<vector<int>>poses(300,vector<int>(0,0));
bool bs(char f,int l,int h){
    int mx=(int)poses[f].size()-1,mn=0;
    while (mx-mn>1) {
        int md=(mx+mn)/2;
        if (poses[f][md]>=l&&poses[f][md]<=h) {
            return true;
        }
        else if (poses[f][md]>h){
            mx=md;
        }
        else if (poses[f][md]<l){
            mn=md;
        }
    }
    if (poses[f][mn]>=l&&poses[f][mn] <=h) {
        return true;
    }
    if (poses[f][mx]>=l&&poses[f][mx]<=h) {
        return true;
    }
    return false;
}
int main()
{
    int sz;
    cin>>sz;
    vector<char>flats(sz);
    set<char>temp;
    for (int i=0; i<sz; i++) {
        cin>>flats[i];
        poses[flats[i]].push_back(i);
        temp.insert(flats[i]);
    }
    for (int i=0; i<300; i++) {
        sort(poses[i].begin(), poses[i].end());
    }
    int ans=1e9;
    vector<int>freq(300,0);
    set<char>dups;
    for (int e=0,s=0; e<sz; e++) {
        freq[flats[e]]++;
        dups.insert(flats[e]);
        if (bs(flats[s], s+1, e)) {
            freq[flats[s]]--;
            if (freq[flats[s]]==0) {
                dups.erase(flats[s]);
            }
            s++;
        }
        if (dups.size()==temp.size()) {
            ans=min(e-s+1,ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			//system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j--]);
			}

			mini = (end - j < mini)? end - j - 1 : mini;
		}
	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			//system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);

		set<char> locSet3;
		for(int i = start; i < end; i++)
			locSet3.insert(arr[i]);
		int start2 = start;
		int end2 = end;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			mini = (end - j < mini)? end - j : mini;
		}

		// to both sides

		while(end2 < n && locSet3.size() != l)
		{
			locSet3.insert(arr[end2]);
			end2++;
			if(locSet3.size() != l && start2 > 0)
				locSet3.insert(arr[--start2]);
		}

		if(locSet3.size() == l)
		{
			/*
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			*/
			mini = (end2 - start2 < mini)? end2 - start2 : mini;
		}

	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			//system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j--]);
			}

			mini = (end - j < mini)? end - j : mini;
		}
	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
//	system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
			mini = (end - start < mini)? end - start : mini;

		// to right

		while(end < n-1 && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
			mini = (end - start2 < mini)? end - start2 : mini;

	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			//system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start - 1 < mini)? j - start - 1 : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j--]);
			}
			mini = (end - j < mini)? end - j : mini;
		}
	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
		//	system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			mini = (end - j < mini)? end - j : mini;
		}
	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


//	http://codeforces.com/contest/701/problem/C

#include<iostream>
using namespace std;

int n = 0;
char arr[100005];
int kinds[125];
int L = 0, l = 0;
int mini = 1000000;

int main(){

	for(int i = 0 ; i < 125; i++)
		kinds[i] = 0;

	cin>>n;
	cin>>arr;

	for(int i = 0; i < n; i++)
		if(!kinds[arr[i]])
		{
			kinds[arr[i]]++;
			L++;
		}

	for(int i = 0 ; i < 125; i++)
		kinds[i] = 0;

	int j = 0;
	for(int i = 0; i < n; i++)
	{
		for(;j < n && l != L; j++)
		{
			if(!kinds[arr[j]])
				l++;
			kinds[arr[j]]++;
		}
		if(l == L)
			mini = (mini > j - i)? j - i : mini;
		kinds[arr[i]]--;
		if(!kinds[arr[i]])
			l--;
	}

	cout<<mini<<endl;

	//system("PAUSE");
	return 0;
}

/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[1000];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);

		set<char> locSet3;
		for(int i = start; i < end; i++)
			locSet3.insert(arr[i]);
		int start2 = start;
		int end2 = end;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			mini = (end - j < mini)? end - j : mini;
		}

		// to both sides

		while(end2 < n && locSet3.size() != l)
		{
			locSet3.insert(arr[end2]);
			end2++;
			if(locSet3.size() != l && start2 > 0)
				locSet3.insert(arr[--start2]);
		}

		if(locSet3.size() == l)
		{

			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}

			mini = (end2 - start2 < mini)? end2 - start2 : mini;
		}

	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	system("PAUSE");
	return 0;
}
*/


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{ cout<<l<<endl; exit(0);}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
			mini = (end - start < mini)? end - start : mini;

		// to right

		while(end < n-1 && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
			mini = (end - start2 < mini)? end - start2 : mini;

	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


//	http://codeforces.com/contest/701/problem/C

#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[1000];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
	//		system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);

		set<char> locSet3;
		for(int i = start; i < end; i++)
			locSet3.insert(arr[i]);
		int start2 = start;
		int end2 = end;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			mini = (end - j < mini)? end - j : mini;
		}

		// to both sides

		while(end2 < n && locSet3.size() != l)
		{
			locSet3.insert(arr[end2]);
			end2++;
			if(locSet3.size() != l && start2 > 0)
				locSet3.insert(arr[--start2]);
		}

		if(locSet3.size() == l)
		{
			/*
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[--j]);
			}
			*/
			mini = (end2 - start2 < mini)? end2 - start2 : mini;
		}

	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
#include<iterator>
using namespace std;

int n = 0;
char arr[100005];
char kinds[100];
vector<char> arrVec;
int l = 0;
int mini = 1000000;

void Find_Out(int start, int end)
{
	set<char> locSet;
	for(int i = start; i < end; i++)
		locSet.insert(arr[i]);
	if(l == (int)locSet.size())
	{
		if(l == end - start)
		{
			cout<<l<<endl;
			//system("PAUSE");
			exit(0);
		}
		//cout<<" # "<<start<<" "<<end<<endl;
		Find_Out(start, start + (end - start)/2);
		Find_Out(start + (end - start)/2, end);
	}
	else
	{
		set<char> locSet2;
		for(int i = start; i < end; i++)
			locSet2.insert(arr[i]);
		int start2 = start;

		// to left

		while(start > 0 && locSet.size() != l)
		{
			start--;
			locSet.insert(arr[start]);
		}
		if(locSet.size() == l)
		{
			int j = start;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j++]);
			}

			mini = (j - start < mini)? j - start : mini;
		}

		// to right

		while(end < n - 1 && locSet2.size() != l)
		{
			locSet2.insert(arr[end]);
			end++;
		}
		if(locSet2.size() == l)
		{
			int j = end;
			set<char> auxSet;
			while(auxSet.size() != l)
			{
				auxSet.insert(arr[j--]);
			}
			mini = (end - j < mini)? end - j : mini;
		}
	}
}

int main(){

	cin>>n;
	cin>>arr;

	set<char> arrSet;
	for(int i = 0; i < n; i++)
		arrSet.insert(arr[i]);

	set<char>::iterator it;
	for(it = arrSet.begin(); it != arrSet.end(); it++)
		kinds[l++] = *it;

	Find_Out(0, n);

	cout<<mini;

	cout<<endl;
	//system("PAUSE");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <ctime>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;
const int INF = 1e9 + 7;

#define mp make_pair

int main() {
#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	string s;
	getline(cin, s);
	getline(cin, s);

	vector<pair<int,int>> v(n);
	map<char, int> M;
	int diff = 0;
	int lb = 0;
	for (int i = 0; i < n; ++i) {
		if (!M.count(s[i])) {
			M[s[i]] = i;
			++diff;
			v[i] = mp(lb, diff);
		}
		else {
			M[s[i]] = i;
			while (M[s[lb]] > lb) {
				++lb;
			}
			v[i] = mp(lb, diff);
		}
	}

	int ans = n;
	for (int i = 0; i < v.size(); ++i) {
		if (v[i].second == diff) {
			ans = min(ans, i - v[i].first + 1);
		}
	}
	cout << ans;

	return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
	long n, cnt = 0, ans = 100001, cur_ans = 0, size, i;
	map<char, long> mas;
	cin >> n;
	string s;
	cin >> s;
	for (i = 0; i < n; i++){
		mas[s[i]] = 0;
	}

	size = mas.size();

	for (i = 0; i < n; i++){
		if (mas[s[i]] == 0)
			cnt++;
		mas[s[i]]++;
		cur_ans++;

		while (cnt == size){
			if (ans > cur_ans)
				ans = cur_ans;
			mas[s[i - cur_ans + 1]]--;
			if (mas[s[i - cur_ans + 1]] == 0)
				cnt--;
			cur_ans--;
		}
	}

	cout << ans << endl;

	return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
	long n, cnt = 0, ans = 100001, cur_ans = 0, size, i;
	map<char, char> mas;
	cin >> n;
	string s;
	cin >> s;
	for (i = 0; i < n; i++){
		mas[s[i]] = 0;
	}

	size = mas.size();

	for (i = 0; i < n; i++){
		if (mas[s[i]] == 0)
			cnt++;
		mas[s[i]]++;
		cur_ans++;

		while (cnt == size){
			if (ans > cur_ans)
				ans = cur_ans;
			mas[s[i - cur_ans + 1]]--;
			if (mas[s[i - cur_ans + 1]] == 0)
				cnt--;
			cur_ans--;
		}
	}

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <vector>
#include<cctype>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<stdlib.h>
#include<ctime>
#include<iterator>
#include <deque>
#include <sstream>
#include<queue>
#include<cstdlib>
#include<climits>
#include<complex>

#define fn(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define mk(f,s) make_pair((f),(s))

using namespace std;

typedef long long ll;
typedef pair<int ,int > pp;

typedef vector<int  > v1;
typedef vector<pp  > vpp;
typedef vector<bool  > vb;
typedef vector<char  > vc;
typedef vector<vector<int > > v2;
typedef map<int ,int > mf;
typedef map<int ,vpp > mv;

int const siz = 1e5,not = 1e9;

char s[siz+1];
int cum[53][siz+1];
bool let[52] = {};
int all ;

int bs(int l,int r){
	int f = l, best = not;
	while(f <= r){
		int mid = (f+r) / 2;
		int c = 0,len = 0;
		fn(i,52){
			if(cum[i][mid] - cum[i][l] != 0){
				c++;
				len += cum[i][mid] - cum[i][l];
			}
		}

		if(c < all){
			f = mid+1;
		}else{
			best = min(best,len);
			r = mid-1;
		}
	}

	return best;
}

int main(){
	int n;
	//cout<<'Z' - 'A' + 26<<endl;
	scanf("%d%s",&n,s);

	fn(i,n){
		fn(j,52){
			if(s[i] - 'a' == j && s[i] >= 'a'){
				cum[j][i+1] = cum[j][i] + 1;
				let[j] = true;
			}
			else if(s[i] - 'A' + 26 == j && s[i] <= 'Z'){
				cum[j][i+1] = cum[j][i] + 1;
				let[j] = true;
			}
			else cum[j][i+1] = cum[j][i] ;
		}
	}

	fn(i,52)
		if(let[i])
			all++;

	int mn = not;
	for(int i = 0;i < n;i++){
		mn = min(bs(i,n),mn);
	}

	printf("%d\n",mn);
	return 0;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int n, cur, pos, ans;
string s;
map <char, int> m;
int main()
{
	cin >> n;
	cin >> s;
	for (int i = 0;i < n;i++) {
		m[s[i]]++;
		if (m[s[i]] > 1)
		{
			while (m[s[pos]] > 1) {
				pos++;
				m[s[pos]]--;
			}
			ans = min(ans, i - pos + 1);
		}
		else ans = i - pos + 1;
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int n, cur, pos, ans;
string s;
map <char, int> m;
int main()
{
	cin >> n;
	cin >> s;
	for (int i = 0;i < n;i++) {
		m[s[i]]++;
		if (m[s[i]] > 1)
		{
			while (m[s[pos]] > 1) {
				m[s[pos]]--;
				pos++;
			}
			ans = min(ans, i - pos + 1);
		}
		else ans = i - pos + 1;
	}
	cout << ans << endl;
	return 0;
}


	//============================================================================
	// Name        : ecpc.cpp
	// Author      : Mohamed Fawzy
	// Version     :
	// Copyright   : Your copyright notice
	// Description : Hello World in C++, Ansi-style
	//============================================================================

#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<map>
#include<utility>
using namespace std;

int A[60],AA[60];

int main()
{
	string s;
	int n, pos=0, cnt=0, R=-1;
	map<char, int>occ;
	cin>>n>>s;
	for(int i=0 ; i<n ; i++)
	{
		if(A[s[i]-'A']==0)
		{
			A[s[i]-'A']=1;
			cnt++;
		}
	}

	for(int i=0 ; i<n ; i++)
	{
		occ[s[i]]++;
		if(occ[s[i]] >1 )
		{
			while (occ[s[pos]] > 1) {
							occ[s[pos]]--;
							pos++;
						}
			R = min(R , i-pos+1);
		}
		else R = i-pos+1;

		//cout<<R<<endl;
	}

	cout<<R;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int c[128] , t;
int total = 0;
string str;

int main()
{
    int N;
    cin >> N >> str;
    for(int i = 0; i < N; i++)
        c[str[i]] = 1;
    for(int i = 0; i < N; i++)
    {
        if(c[str[i]] == 1)
            total++;
        c[str[i]] = 0;
    }

    int ans = 1000*1000*100;
    for(int i = 0, j = -1; i < N; i++)
    {
        while(t < total && j +1 < N)
            if(!c[str[++j]]++)
                t++;
        if(t == total) ans = std::min(ans,j-i);
        if(!--c[str[i]]) --t;
    }
    cout << ans+1;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<map>
using namespace std;
const int mod=1e9+7;

char c[100100];

void solve(int n){
	int i,j=-1,m=n,l=1,r,k,a[150];
	gets(c);
	gets(c);
	for(i=0;i<150;i++)a[i]=0;
	for(i=0;i<n;i++)a[c[i]]++;
	k=0;
	for(i=0;i<150;i++)
		if(a[i]>0)
			k++;
	for(i=0;i<150;i++)a[i]=0;

	l=0;
	r=0;
	a[c[0]]++;
	j=1;
	for(l=0;l<n;l++){
		while(r+1<n&&j<k){
			r++;
			a[c[r]]++;
			if(a[c[r]]==1)
				j++;
		}
		if(j==k)
			m=min(m,r-l+1);
		a[c[l]]--;
		if(a[c[l]]==0)
			j--;
	}

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

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif _DEBUG

	int n,m,x,y,i,j,q=0;
	while(scanf("%d",&n)!=EOF){
		solve(n);
		printf("\n");
	}

	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<map>
using namespace std;
const int mod=1e9+7;

char c[100100];

void solve(int n){
	int i,j=-1,m=n,l=1,r,k,a[150];
	gets(c);
	gets(c);
	for(i=0;i<150;i++)a[i]=0;
	for(i=0;i<n;i++)a[c[i]]++;
	k=0;
	for(i=0;i<150;i++)if(a[i]>0)k++;
	for(i=0;i<150;i++)a[i]=0;

	l=0;
	r=0;
	a[c[0]]++;
	j=1;
	for(l=0;l<n;l++){
		while(r<n&&j<k){
			r++;
			a[c[r]]++;
			if(a[c[r]]==1)
				j++;
		}
		if(j==k)
			m=min(m,r-l+1);
		a[c[l]]--;
		if(a[c[l]]==0)
			j--;
	}

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

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif _DEBUG

	int n,m,x,y,i,j,q=0;
	while(scanf("%d",&n)!=EOF){
		solve(n);
		printf("\n");
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int k = 0;
	int min = 100000000;
	for (int i = 0; i <n; ++i)
	{
		if (k == g.size())
		{
			if (i - nach < min) min = i - nach;
			k = 0;
			for (int z = 0; z < g.size(); ++z)
			{
				g[z].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
					break;
				}
			}
		}
	}
	for (int i = 0; i < g.size(); ++i)
	{
		g[i].was = false;
	}
	k = 0;
	for (int i = n-1; i >=0; --i)
	{
		if (k == g.size())
		{
			if (nach-i < min) min = nach-i;
			k = 0;
			for (int z = 0; z < g.size(); ++z)
			{
				g[z].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
					break;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
int k = 0;
vector <int> v(52);
vector <int> v1(52);
int z = 0;
bool est(int u)
{
	int a;
	if (int(s[u]) < 97) a=int(s[u]) - 39;
	else a =int(s[u]) - 97;
	if (v1[a] != 1)
	{
		k++;
	}
	v1[a] = 1;
	if (k == z) return true;
	return false;
}
int main()
 {
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (int(s[i]) < 97)
		{
			v[int(s[i]) - 39] = 1;
		}
		else
		{
			v[int(s[i]) - 97] = 1;
		}
	}
	for (int i = 0; i < 52; ++i)
	{
		z += v[i];
	}
	int  nach = 0;
	int mi = 100000000;
	for (int i = 0; i <n; ++i)
	{
		if (est(i))
		{
			mi = min(mi, i - nach+1);
			nach++;
			i = nach-1;
			k = 0;
			v1.clear();
			v1.resize(52);
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;
int n1 = 0;
int mi = 100000000;
int n;
void BFS(int v)
{
	queue<int> q;
	q.push(v);
	int k = 0;
	while (!q.empty())
	{
		int b = q.front();
		if (q.front() >= n)
		{
			if (k >= g.size())
			{
				n1 = b - v;
				break;
			}
			q.pop();
			continue;
		}
		char a = s[q.front()];
		q.pop();
		if (k >=g.size())
		{
				n1= b-v;
				break;
		}
		for (int i = 0; i < g.size(); ++i)
		{
			if (a == g[i].a)
			{
				if (!g[i].was) ++k;
				g[i].was = true;
				q.push(b + 1);
				break;
			}
		}
	}
	if (n1 < mi && k==g.size()) mi = n1;
	return;
}

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	for (int i = 0; i < n; ++i)
	{
		BFS(i);
		for (int i = 0; i < g.size(); ++i)
		{
			g[i].was = false;
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int k = 0;
	int min = 100000000;
	for (int i = 0; i <= n; ++i)
	{
		if (k == g.size())
		{
			if (i - nach < min) min = i - nach;
			k = 0;
			for (int i = 0; i < g.size(); ++i)
			{
				g[i].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
				}
			}
				for (int j = nach+1; j < i; ++j)
				{
					if (s[nach] == s[j])
					{
						nach++;
						j = nach + 1;
					}
				}
			}
		}
	cout << min << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

#define mp make_pair
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define forit(i,c) for(i=(c).begin(); i!=(c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

typedef map<int, int> mii;
typedef map<char, int> mci;

const double PI = 3.1415926535897932384626433832795;

bool check(mci& m)
{
	mci::iterator it;
	forit(it, m)
	{
		if (it->second < 1) return false;
	}
	return true;
}

int main()
{
#ifdef _VLYZ
	freopen("input.txt", "r", stdin);
#else
	//freopen("abc.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif

	int64 n;
	cin >> n;
	string s;
	cin >> s;
	mci m;
	forn(i, n)
	{
		m[s[i]] = 0;
	}
	int j = 0;
	int res = 1000000;
	forn(i, n)
	{
		bool f = check(m);
		while (j<n && !f)
		{
			m[s[j]]++;
			++j;
		}
		if (f) res = min(res, j - i);
		m[s[i]]--;
	}
	cout << res << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;
int k = 0;
bool est(int v)
{
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[v] == g[j].a)
			{
				if (!g[j].was)
				{
					k++;
					g[j].was = true;
				}
				break;
			}
		}
	if (k == g.size()) return true;
	return false;
}
int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int mi = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		if (est(i))
		{
			mi = min(mi, i - nach+1);
			nach++;
			i = nach-1;
			k = 0;
			for (int j = 0; j < g.size(); ++j)
			{
				g[j].was = false;
			}
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;
int n1 = 0;
int mi = 100000000;
int n;
void BFS(int v)
{
	queue<int> q;
	q.push(v);
	int k = 0;
	while (!q.empty())
	{
		int b = q.front();
		if (q.front() >= n)
		{
			if (k >= g.size())
			{
				n1 = b - v;
				break;
			}
			q.pop();
			continue;
		}
		char a = s[q.front()];
		q.pop();
		if (k >= g.size())
		{
			n1 = b - v;
			break;
		}
		for (int i = 0; i < g.size(); ++i)
		{
			if (a == g[i].a)
			{
				if (!g[i].was) ++k;
				g[i].was = true;
				q.push(b + 1);
				break;
			}
		}
	}
	if (n1 < mi && k == g.size()) mi = n1;
	return;
}

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	for (int i = 0; i < n-g.size()+1; ++i)
	{
		BFS(i);
		for (int i = 0; i < g.size(); ++i)
		{
			g[i].was = false;
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int mi = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		bool f = false;
		for (int j = 0; j < g.size(); ++j)
		{
			if (!g[j].was) f = true;
		}
		if (f)
		{
			for (int j = 0; j < g.size(); ++j)
			{
				if (s[i] == g[j].a)
				{
					g[j].was = true;
					break;
				}
			}
		}
		else
		{
			mi = min(mi, i - nach);
			nach++;
			i = nach-1;
			for (int j = 0; j < g.size(); ++j)
			{
				g[j].was = false;
			}
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int k = 0;
	int min = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		if (k == g.size())
		{
			if (i - nach < min) min = i - nach;
			k = 0;
			for (int z = 0; z < g.size(); ++z)
			{
				g[z].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
					break;
				}
			}
		}
	}
	for (int i = 0; i < g.size(); ++i)
	{
		g[i].was = false;
	}
	k = 0;
	for (int i = n; i >=0; --i)
	{
		if (k == g.size())
		{
			if (nach-i < min) min = nach-i;
			k = 0;
			for (int z = 0; z < g.size(); ++z)
			{
				g[z].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
					break;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach=0;
	int k = 0;
	int min = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		if (k == g.size())
		{
			if (i - nach < min) min = i - nach;
			k = 0;
			for (int i = 0; i < g.size(); ++i)
			{
				g[i].was = false;
			}
		}
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					if (k == 0)
					{
						nach = i;
					}
					k++;
					g[j].was = true;
				}
				else
				{
					bool f = false;
					if (s[i] == s[nach]) nach++;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;
int n1 = 0;
int mi = 100000000;
int n;
void BFS(int v)
{
	queue<int> q;
	q.push(v);
	int k = 0;
	while (!q.empty())
	{
		int b = q.front();
		if (q.front() >= n)
		{
			if (k >= g.size())
			{
				n1 = b - v;
				break;
			}
			q.pop();
			continue;
		}
		char a = s[q.front()];
		q.pop();
		if (k >= g.size())
		{
			n1 = b - v;
			break;
		}
		for (int i = 0; i < g.size(); ++i)
		{
			if (a == g[i].a)
			{
				if (!g[i].was) ++k;
				g[i].was = true;
				q.push(b + 1);
				break;
			}
		}
	}
	if (n1 < mi && k == g.size()) mi = n1;
	return;
}

int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	for (int i = 0; i < n-g.size(); ++i)
	{
		BFS(i);
		for (int i = 0; i < g.size(); ++i)
		{
			g[i].was = false;
		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
string s1;
struct Node
{
	char a;
	bool was;
	Node()
	{
		was = false;
	}
};
vector <Node> g;
bool est(int u, int v)
{
	int k = 0;
	for (int i = u; i < v; ++i)
	{
		for (int j = 0; j < g.size(); ++j)
		{
			if (s[i] == g[j].a)
			{
				if (!g[j].was)
				{
					k++;
					g[j].was = true;
				}
				break;
			}
		}
	}
	for (int j = 0; j < g.size(); ++j)
	{
		g[j].was = false;
	}
	if (k == g.size()) return true;
	return false;
}
int main()
{
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	string s2 = s;
	sort(s2.begin(), s2.end());
	s1.push_back(s2[0]);
	for (int i = 0; i < s.size() - 1; ++i)
	{
		if (s2[i] == s2[i + 1]) continue;
		else s1.push_back(s2[i + 1]);
	}
	g.resize(s1.size());
	for (int i = 0; i < s1.size(); ++i)
	{
		g[i].a = s1[i];
	}
	int  nach = 0;
	int mi = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		if (est(nach, i))
		{
			mi = min(mi, i - nach);
			nach++;
			i = nach-1;

		}
	}
	cout << mi << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
const double Pi = 3.1415926536;
string s;
vector <int> v(52);
vector <int> v1(52);
int z = 0;
bool est()
{
	int k = 0;
	for (int i = 0; i < 52; ++i)
	{
		if (v1[i] > 0)
		{
			k++;
		}
	}
	if (k == z) return true;
	return false;
}
int main()
 {
#ifdef _KOCHERGIN
	freopen("abc.txt", "r", stdin);
#else
	//freopen("sample.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (int(s[i]) < 97)
		{
			v[int(s[i]) - 39] = 1;
		}
		else
		{
			v[int(s[i]) - 97] = 1;
		}
	}
	for (int i = 0; i < 52; ++i)
	{
		z += v[i];
	}
	int  nach = 0;
	int mi = 100000000;
	for (int i = 0; i <=n; ++i)
	{
		if (est())
		{
			mi = min(mi, i - nach);
			if (int(s[nach]) < 97)
			{
				v1[int(s[nach]) - 39]--;
			}
			else
			{
				v1[int(s[nach]) - 97]--;
			}
			nach++;
			i--;
		}
		else
		{
			if (i == n) continue;
			if (int(s[i]) < 97)
			{
				v1[int(s[i]) - 39]++;
			}
			else
			{
				v1[int(s[i]) - 97]++;
			}
		}
	}
	cout << mi << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

	int M[100010][260];
int main()
{
#ifdef _DEBUG
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<100010;i++)
		for(int j=0;j<260;j++)
			M[i][j]=0;

	int h[260];
	for(int j=0;j<260;j++)
		h[j]=0;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=0;j<260;j++)
		{
			M[i][j]=M[i-1][j];
		}
		M[i][(int)s[i-1]]++;
		h[(int)s[i-1]]++;
	}
	int kol=0;
	for(int i=0;i<260;i++)
		if(h[i]>0)
			kol++;

	int min=100000000;

	for(int i=1;i<n+1;i++)
	{
		int gg=0;
		for(int j=0;j<260;j++)
		{
			if(M[n][j]-M[i][j]>0)
				gg++;
		}
		if(gg==kol)
		{
			int l=i;
			int r=n;
			int m;

			while(r-l>1)
			{
				m=(l+r)/2;
				int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[m][j]-M[i][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					r=m;
				}
				else
					l=m;
			}
			int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[r][j]-M[i][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					if(min>r-i)
						min=r-i;
				}
				else
					if(min>l-i)
						min=l-i;
		}
	}
	cout<<min;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

	int M[100010][260];
int main()
{
#ifdef _DEBUG
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<100010;i++)
		for(int j=0;j<260;j++)
			M[i][j]=0;

	int h[260];
	for(int j=0;j<260;j++)
		h[j]=0;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=0;j<260;j++)
		{
			M[i][j]=M[i-1][j];
		}
		M[i][(int)s[i-1]]++;
		h[(int)s[i-1]]++;
	}
	int kol=0;
	for(int i=0;i<260;i++)
		if(h[i]>0)
			kol++;

	int min=100000000;

	for(int i=1;i<n+1;i++)
	{
		int gg=0;
		for(int j=0;j<260;j++)
		{
			if(M[n][j]-M[i-1][j]>0)
				gg++;
		}
		if(gg==kol)
		{
			int l=i;
			int r=n;
			int m;

			while(r-l>1)
			{
				m=(l+r)/2;
				int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[m][j]-M[i][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					r=m;
				}
				else
					l=m;
			}
			int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[r][j]-M[i][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					if(min>r-i)
						min=r-i;
				}
				else
					if(min>l-i)
						min=l-i;
		}
	}
	cout<<min+1;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

	int M[100010][260];
int main()

{
#ifdef _DEBUG
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<100010;i++)
		for(int j=0;j<260;j++)
			M[i][j]=0;

	int h[260];
	for(int j=0;j<260;j++)
		h[j]=0;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=0;j<260;j++)
		{
			M[i][j]=M[i-1][j];
		}
		M[i][(int)s[i-1]]++;
		h[(int)s[i-1]]++;
	}
	int kol=0;
	for(int i=0;i<260;i++)
		if(h[i]>0)
			kol++;

	int min=100000000;

	for(int i=1;i<n+1;i++)
	{
		int gg=0;
		for(int j=0;j<260;j++)
		{
			if(M[n][j]-M[i-1][j]>0)
				gg++;
		}
		if(gg==kol)
		{
			int l=i;
			int r=n;
			int m;

			while(r-l>1)
			{
				m=(l+r)/2;
				int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[m][j]-M[i-1][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					r=m;
				}
				else
					l=m;
			}
			int gg1=0;
				for(int j=0;j<260;j++)
				{
					if(M[r][j]-M[i-1][j]>0)
						gg1++;
				}
				if(gg1==kol)
				{
					if(min>r-i)
						min=r-i;
				}
				else
					if(min>l-i)
						min=l-i;
		}
	}
	cout<<min+1;
}


#pragma comment(linker, "/STACK:250000000")
#define _USE_MATH_DEFINES
#define LL long long
#define INF (LL)2147483000
#define EPS (1e-7)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define MOD 1000000007

#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
//#include <stdio.h>

using namespace std;

class animal {
public:
  int n, index;
  bool operator < (animal another) {
    return n < another.n;
  }
};

long long gcd( long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}

LL pow_mod(LL x, LL a) {
	if (a == 0)
		return 1;
	if (a == 1)
		return x;
	LL res = pow_mod(x, a / 2);
	res = (res * res) % MOD;
	if (a % 2)
		res = res * x % MOD;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);

	LL n;
	cin >> n;
	string s;
	cin >> s;
	map<char, int> freq;
	set<char> freep;
	for (int i = 0; i < s.size(); ++i) {
		freep.insert(s[i]);
	}
	int left = 0, right = 0, answ = INF;
	char c;
	while (right != n || freep.size() == 0) {
		if (freep.size() != 0) {
			c = s[right];
			freq[c]++;
			freep.erase(c);

			right++;
		} else {
			c = s[left];
			freq[c]--;
			if (freq[c] <= 0) {
				freep.insert(c);
			}

			left++;
		}

		if (freep.size() == 0) {
			answ = min( answ, right - left);
		}

	}

	cout << answ << endl;

	return 0;
}

/*
5 100 2 3
30 90
70 90
110 70
70 50
30 50

*/
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <functional>
#include <string>
#include <set>

using namespace std;

#define mp make_pair
#define sqr(x) ((x) * (x))

typedef long double ld;
typedef long long ll;

const int MAXN = 1e5;
const ld PI = acos(-1.0);
const ld EPS = 1e-14;
const ld INF = 1e7;

set<int> SE;
char a[MAXN];
int pokemons_cnt[256];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d\n", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%c", &a[i]);
		SE.insert(a[i]);
	}

	int pokemon_types = SE.size();
	int cur_types = 0;
	int ans = n;

	for (int left = 0, right = -1; left < n; ++left) {
		while(cur_types != pokemon_types && right < n - 1) {
			++right;
			if (pokemons_cnt[a[right]] == 0) {
				++cur_types;
			}
			++pokemons_cnt[a[right]];
		}

		if (cur_types == pokemon_types) {
			ans = min(ans, right - left + 1);
		}

		--pokemons_cnt[a[left]];
		if (!pokemons_cnt[a[left]]) {
			--cur_types;
		}
	}

	printf("%d", ans);

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <functional>
#include <string>
#include <set>

using namespace std;

#define mp make_pair
#define sqr(x) ((x) * (x))

typedef long double ld;
typedef long long ll;

const int MAXN = 1e5;
const ld PI = acos(-1.0);
const ld EPS = 1e-14;
const ld INF = 1e7;

set<int> SE;
char a[MAXN];
int pokemons_cnt[256];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d\n", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%c", &a[i]);
		SE.insert(a[i]);
	}

	int pokemon_types = SE.size();
	int cur_types = 0;
	int ans = n;

	for (int left = 0, right = -1; left < n; ++left) {
		while(cur_types != pokemon_types && right < n) {
			++right;
			if (pokemons_cnt[a[right]] == 0) {
				++cur_types;
			}
			++pokemons_cnt[a[right]];
		}

		if (cur_types == pokemon_types) {
			ans = min(ans, right - left + 1);
		}

		--pokemons_cnt[a[left]];
		if (!pokemons_cnt[a[left]]) {
			--cur_types;
		}
	}

	printf("%d", ans);

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100100
char str[maxn];
int big[30];//分别记录某种大写字母出现的个数
int lit[30];//分别记录某种小写字母出现的个数
int main()
{
    int n,i,a,j;
    while(scanf("%d",&n)!=EOF)
    {
        memset(big,0,sizeof(big));
        memset(lit,0,sizeof(lit));
        scanf("%s",str);
        int sum=0;
        for(i=0;i<n;++i)
        {
            if('a'<=str[i]&&str[i]<='z')//统计字符串中一共有多少种字符
            {
                a=str[i]-'a';
                if(!lit[a])
                {
                    sum++;
                    lit[a]=1;
                }
            }
            else
            {
                a=str[i]-'A';
                if(!big[a])
                {
                    sum++;
                    big[a]=1;
                }
            }
        }
        int cnt=0;
        int start=0,ans=n;
        memset(big,0,sizeof(big));
        memset(lit,0,sizeof(lit));
        for(i=0;i<n;++i)
        {
            if('a'<=str[i]&&str[i]<='z')
            {
                a=str[i]-'a';
                if(!lit[a])
                    cnt++;
                lit[a]++;
            }
            if('A'<=str[i]&&str[i]<='Z')
            {
                a=str[i]-'A';
                if(!big[a])
                    cnt++;
                big[a]++;
            }
            if(cnt==sum)//子串包含所有字符种类时，子串首部往后移动，并记录最短的满足条件的子串长度
            {
                while(cnt==sum)
                {
                    if(i-start+1<ans)
                        ans=i-start+1;
                    if('a'<=str[start]&&str[start]<='z')
                    {
                        a=str[start]-'a';
                        lit[a]--;
                        if(!lit[a])
                            cnt--;
                    }
                    if('A'<=str[start]&&str[start]<='Z')
                    {
                        a=str[start]-'A';
                        big[a]--;
                        if(!big[a])
                            cnt--;
                    }
                    start++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100000
char s1[MAX+1],s2[100];
int sum;
int find(int x,int y)
{
	int a,b=0,judge=0,c;
	for(a=x;a<=y;a++)
	{
		if(a==x)
			s2[b++]=s1[a];
		else
		{
			for(c=0;c<b;c++)
				if(s1[a]==s2[c])
				{
					judge=1;
					break;
				}
				if(judge==0)
					s2[b++]=s1[a];
		}
		judge=0;
	}
	if(b>=sum)return 1;
	else return 0;
}
int main()
{
	int n,length,x,y,a,b=0,c,judge,fina,all;
	char s3[100];
	while(scanf("%d",&n)!=EOF)
	{
		judge=0;
		getchar();
		gets(s1);
		length=strlen(s1);
		s3[0]=s1[0];b=1;
		for(a=1;a<length;a++)
		{
			for(c=0;c<b;c++)
			{
				if(s1[a]==s3[c])
				{
					judge=1;
					break;
				}
			}
				if(judge==0)
					s3[b++]=s1[a];
		judge=0;
		}
      sum=b;all=1;
	  for(x=sum;x<=length;x++)
	  {
		for(a=0;a+x-1<length;a++)
		{
			fina=find(a,a+x-1);
			if(fina==1){all=x;break;}
		}
		if(fina==1)break;
	  }
	  printf("%d\n",all);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100000
char s1[MAX+1],s2[100];
int sum;
int find(int x,int y)
{
	int a,b=0,judge=0,c,fina=MAX;
	for(a=x;a<y;a++)
	{
		if(a==x)
			s2[b++]=s1[a];
		else
		{
			for(c=0;c<b;c++)
				if(s1[a]==s2[c])
				{
					judge=1;
					break;
				}
				if(judge==0)
					s2[b++]=s1[a];
		}
		if(b==sum)
		{
			fina=a-x+1;
			break;
		}
		judge=0;
	}
	return fina;
}
int main()
{
	int n,length,x,y,a,b=0,c,judge,fina,all,min=MAX;
	char s3[100];
	while(scanf("%d",&n)!=EOF)
	{
		judge=0;min=MAX;
		getchar();
		gets(s1);
		length=strlen(s1);
		s3[0]=s1[0];b=1;
		for(a=1;a<length;a++)
		{
			for(c=0;c<b;c++)
			{
				if(s1[a]==s3[c])
				{
					judge=1;
					break;
				}
			}
				if(judge==0)
					s3[b++]=s1[a];
		judge=0;
		}
      sum=b;all=1;
	  for(x=0;x+sum<=length;x++)
	  {
			fina=find(x,length);
		if(fina<min)min=fina;
	  }
	  printf("%d\n",min);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <map>
using namespace std;
int main() {
	map < char, set<int> > mp;
		int n;
		cin >> n;
		int ans = 100000;
		for (int i = 1; i <= n; i++) {
			char p;
			cin >> p;
			mp[p].insert(i);
		}
		for (int i = 1; i <= n; i++) {
			bool fl = 1;
			int x = 0;
			for (map<char, set<int>>::iterator it = mp.begin(); it != mp.end(); it++) {
				set<int>::iterator a =lower_bound(it->second.begin(), it->second.end(), i);
				if (a == it->second.end()) {
					fl = 0;
				}
				if (a != it->second.end()) {
					x = max(x, *(a));
				}
			}
			if (fl == 1) {
				ans = min(ans, x - i + 1);
			}
			else {
				cout << ans;
				return 0;
			}
		}
		cout << ans;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <map>
using namespace std;
int main() {
	map < char, set<int> > mp;
		int n;
		cin >> n;
		int ans = 100000;
		for (int i = 1; i <= n; i++) {
			char p;
			cin >> p;
			mp[p].insert(i);
		}
		for (int i = 1; i <= n; i++) {
			bool fl = 1;
			int x = 0;
			for (map<char, set<int>>::iterator it = mp.begin(); it != mp.end(); it++) {
				set<int>::iterator a =lower_bound(it->second.begin(), it->second.end(), i);
				if (a == it->second.end()) {
					fl = 0;
				}
				if (a != it->second.end()) {
					x = max(x, *(a));
				}
			}
			if (fl == 1)
				ans = min(ans, x - i + 1);
		}
		cout << ans;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <vector>
using namespace std;
int main() {
	map < char, vector<int> > mp;
		int n;
		cin >> n;
		int ans = 100000;
		for (int i = 1; i <= n; i++) {
			char p;
			cin >> p;
			mp[p].push_back(i);
		}
		for (int i = 1; i <= n; i++) {
			bool fl = 1;
			int x = 0;
			for (map<char, vector<int>>::iterator it = mp.begin(); it != mp.end(); it++) {
				vector<int>::iterator a =lower_bound(it->second.begin(), it->second.end(), i);
				if (a == it->second.end()) {
					fl = 0;
				}
				if (a != it->second.end()) {
					x = max(x, *(a));
				}
			}
			if (fl == 1) {
				ans = min(ans, x - i + 1);
			}
			else {
				cout << ans;
				return 0;
			}
		}
		cout << ans;
}


#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <deque>
#include <math.h>
#include <map>

using namespace std;

const int o = 1000000007;

bool comparefirst(pair<int, int> s1, pair<int, int> s2)
{
	return s1.first > s2.first;
}

bool comparesecond(pair<int, int> s1, pair<int, int> s2)
{
	return s1.second > s2.second;
}

int main()
{
	int kol = 99999999;
	string s;
	char del;
	int arr[130];
	bool boo[130];
	set<char> am;
	cin >> s;
	memset(arr, 0, sizeof(arr));
	memset(boo, 0, sizeof(boo));
	cin >> s;
	int m = s.length();
	for (int i = 0; i < m; i++)
		am.insert(s[i]);
	int x = am.size();
	am.clear();
	int amount = 0;
	int begin = 0;
	int end = begin;
	while (end <= m)
	{
		while (amount < x &&  end <= m)
		{
			arr[s[end]]++;
			if (!boo[s[end]])
			{
				boo[s[end]] = true;
				amount++;
			}
			end++;
		}
		kol = min(kol, end - begin);
		begin++;
		arr[s[begin]]--;
		if (!arr[s[begin]])
		{
			amount--;
			boo[s[begin]] = false;
		}
	}
	cout << kol;
	cin >> m;
	return 0;
}


#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <deque>
#include <math.h>
#include <map>

using namespace std;

const int o = 1000000007;

bool comparefirst(pair<int, int> s1, pair<int, int> s2)
{
	return s1.first > s2.first;
}

bool comparesecond(pair<int, int> s1, pair<int, int> s2)
{
	return s1.second > s2.second;
}

int main()
{
	int kol = 99999999;
	string s;
	char del;
	int arr[130];
	bool boo[130];
	set<char> am;
	cin >> s;
	memset(arr, 0, sizeof(arr));
	memset(boo, 0, sizeof(boo));
	cin >> s;
	int m = s.length();
	for (int i = 0; i < m; i++)
		am.insert(s[i]);
	int x = am.size();
	am.clear();
	int amount = 0;
	int begin = 0;
	int end = begin;
	if (m == 1)
	{
		cout << 1;
		return 0;
	}
	while (end <= m)
	{
		while (amount < x &&  end <= m)
		{
			arr[s[end]]++;
			if (!boo[s[end]])
			{
				boo[s[end]] = true;
				amount++;
			}
			end++;
		}
		kol = min(kol, end - begin);
		arr[s[begin]]--;
		if (!arr[s[begin]])
		{
			amount--;
			boo[s[begin]] = false;
		}
		begin++;
	}
	cout << kol;
	cin >> m;
	return 0;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char let[100100];
int cou[100];
int main()
{
    int i,n;
    scanf("%d",&n);
    getchar();
    memset(cou,0,sizeof(cou));
    int ans=0;
    int s=1;
    for(i=1; i<=n; i++)
    {
        scanf("%c",&let[i]);
        if(cou[let[i]-'A']==0) ans=i-s+1;
        cou[let[i]-'A']++;
        while(s<i)
        {
            if(cou[let[s]-'A']>1)
            {
                cou[let[s]-'A']--;
                s++;
            }
            else break;
        }
        if(ans>i-s+1) ans=i-s+1;
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
char let[100100];
int cou[100];
int main()
{
    int i,n;
    scanf("%d",&n);
    getchar();
    memset(cou,0,sizeof(cou));
    int ans=0;
    int s=1;
    for(i=1; i<=n; i++)
    {
        scanf("%c",&let[i]);
        if(cou[let[i]-'A']==0) ans=i-s+1;
        cou[let[i]-'A']++;
        while(s<i)
        {
            if(cou[let[s]-'A']>1)
            {
                cou[let[s]-'A']--;
                s++;
            }
            else break;
        }
        if(ans>i-s+1) ans=i-s+1;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <math.h>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define endl "\n"
#define mp make_pair
#define pll pair<ll,ll>

/*
#include <fstream>
ifstream in("input.txt");
ofstream out("output.txt");

#define cin in
#define cout out
/**/

int main()
{
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;

	string s;
	cin >> s;

	set<char> x;
	for (int i = 0; i < s.size(); ++i)
		x.insert(s[i]);
	int xx = x.size();

	map<char, int> mapka;

	int mn = 1000000;
	int l = 0, r = 0;
	while (l < n)
	{
		while (r < n && mapka.size() != xx)
			mapka[s[r++]]++;

		if (mapka.size() == xx)
			mn = min(mn, r-l);

		mapka[s[l]]--;
		if (mapka[s[l]] == 0)
			mapka.erase(mapka.find(s[l]));
		++l;
	}
	cout << mn;

	return 0;
}


#include<iostream>
#include<memory.h>
#include<algorithm>
#define LL long long
using namespace std;

const int maxn = 100000 + 5;
int arr[maxn];
int kinds[26 * 2];

int main() {
	int n;
	while (cin >> n) {
		int tot = 0;
		memset(kinds, 0, sizeof(kinds));
		char c;
		for (int i = 0; i < n; ++i) {
			cin >> c;
			if (c - 'a' >= 0)
				arr[i] = c - 'a';
			else
				arr[i] = 26 + c - 'A';

			if (!kinds[arr[i]]) {
				kinds[arr[i]] = 1;
				tot++;
			}
		}

		int l = 0;
		memset(kinds, 0, sizeof(kinds));
		int cnt = 0;
		int res = 100000 + 10;
		for (int i = 0; i < n; ++i) {
			if (!kinds[arr[i]])
				cnt++;
			kinds[arr[i]]++;
			if (cnt < tot) continue;
			while (l <= i && cnt == tot) {//left boundary move
				kinds[arr[l]]--;
				l++;
				if (!kinds[arr[l- 1]]) {
					cnt--;
					res = min(i - l + 2, res);
				}
			}
		}
		cout << res << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <queue>
#include <map>
#include <set>
#include <stack>

using namespace std;

const long long INF = 1000000000;

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	string s;
	set<char> lit;

	char x;
	scanf("%c", &x);
	for (int i = 0; i < n; i++)
	{

		scanf("%c", &x);
		lit.insert(x);
		s += x;
	}

	vector<int> len(n);
	for (set<char>::iterator it = lit.begin(); it != lit.end(); it++)
	{
		int last = -1;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == *it)
			{
				last = i;
			}

			len[i] = last == -1 ? INF : max(len[i], i - last + 1);
		}
	}

	int ans = *min_element(len.begin(), len.end());
	printf("%d", ans);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <map>

using namespace std;
int poks = 0;

map<char,int> freq;
int main()
{
	int mini = 1000001;
	int n;
	char s[100005], ch;
	scanf("%d\n", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%c", &ch);
		s[i] = ch;
		freq[ch] = 1;
	}

	poks = freq.size();
	freq.clear();

	int i = 0;
	for (int j = 0; j < n; ++j)
	{
		freq[s[j]]++;
		while(freq.size() == poks)
		{
			if (j - i + 1 < mini)
				mini = j - i + 1;
			--freq[s[i]];
			if (freq[s[i]] == 0)
				freq.erase(s[i]);
			++i;
		}
	}
	printf("%d", mini);
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a, b[1050], c,  l, r, q,n,m,sum,ans,g;
string s;
const int inf = 999999999;
int main()
{
	while (cin>>n) {
	    getline(cin, s);
	    getline(cin, s);
		sum=g=c= 0;
		ans = 99999999;
		memset(b, 0, sizeof(b));
		for (int i = 0; i <s.size(); ++i)
			if ((s[i]>='A'&&s[i] <= 'Z')||(s[i] >= 'a'&&s[i] <= 'z'))
			if (b[int(s[i])]==0) {
				++sum;
				b[int(s[i])] = 1;
			}
		memset(b, 0, sizeof(b));
		for (int i = 0; i < s.size(); ++i)
			if ((s[i] >= 'A'&&s[i] <= 'Z') || (s[i] >= 'a'&&s[i] <= 'z')){
			if (b[int(s[i])] == 0) ++g;
			if (g == sum&&c+1 <ans) ans = c+1;

			++b[int(s[i])];
			while (b[int(s[i - c])] > 1) {
				--b[int(s[i - c])];
				--c;
			}
			++c;
		}

		cout << ans << endl;

	}

}