import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.SortedSet;
import java.util.Set;
import java.util.NavigableSet;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            char[] c = in.next().toCharArray();
            NavigableSet<Integer> ones = new TreeSet<>();
            NavigableSet<Integer> zeros = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                if (c[i] == '0') zeros.add(i);
                else ones.add(i);
            }
            if (ones.isEmpty() || zeros.isEmpty() || ones.last() - ones.first() + 1 <= k || zeros.last() - zeros.first() + 1 <= k) {
                out.println("tokitsukaze");
                return;
            }
            if (check(ones, n, k) && check(zeros, n, k)) {
                out.println("quailty");
                return;
            }
            out.println("once again");
        }

        private boolean check(NavigableSet<Integer> ones, int n, int k) {
            for (int i = 0; i + k <= n; i++) {
                int left = ones.first();
                int right = ones.last();
                if (left >= i) {
                    left = ones.higher(i + k - 1);
                }
                if (right < i + k) {
                    right = ones.lower(i);
                }
                if (right - left + 1 > k) {
                    return false;
                }
            }
            return true;
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            if (c < 0) {
                return null;
            }
            while (c >= 0 && !isWhiteSpace(c)) {
                sb.appendCodePoint(c);
                c = read();
            }
            return sb.toString();
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main implements Runnable {
    public InputReader in;
    public PrintWriter out;

    public void solve() throws Exception {
        // solution goes here
        int N = in.nextInt();

        int[] houses = new int[N];
        boolean[] exist = new boolean[52];

        for (int i = 0; i < N; i++) {
            char c = in.nextChar();
            if ('a' <= c && c <= 'z') {
                houses[i] = 26 + (c - 'a');
            } else {
                houses[i] = (c - 'A');
            }
            exist[houses[i]] = true;
        }

        int[][] pokemons = new int[N][52];

        pokemons[0][houses[0]] = 1;

        for (int i = 1; i < N; i++) {
            System.arraycopy(pokemons[i-1], 0, pokemons[i], 0, pokemons[i].length);
            pokemons[i][houses[i]]++;
        }

        int uniques = 0;
        for(boolean bool : exist)
            if (bool)
                uniques++;

        if (uniques == 1) {
            out.print(1);
            return;
        }

        int last_variant = -1;
        for (int i = 0; i < N-1; i++) {
            if (pokemons[i][houses[i]] == pokemons[N-1][houses[i]]) {
                last_variant = i;
                break;
            }
        }

        int minimum = N;

        for (int i = 0; i <= last_variant; i++) {
            if (houses[i] == houses[i+1])
                continue;

            // binary search

            int low = i+1;
            int high = N-1;

            while (low < high) {
                int mid = (low + high) / 2;

                boolean allPresent = true;
                for (int j = 0; j < 52; j++) {
                    if (j != houses[i] && exist[j] && pokemons[mid][j] == pokemons[i][j]) {
                        allPresent = false;
                        break;
                    }
                }

                if (allPresent) {
                    high = mid; // infinite??
                } else {
                    low = mid + 1;
                }
            }

            minimum = min(minimum, low - i + 1);

        }

        out.print(minimum);
    }

    public void run() {
        try {
            in = new InputReader(System.in);
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
            Locale.setDefault(Locale.US);
            int tests = 1;
            while (tests-- > 0) {
                solve();
            }
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(7);
        }
    }

    static int abs(int x) {
        return x < 0 ? -x : x;
    }

    static int max(int a, int b) {
        return a > b ? a : b;
    }

    static int min(int a, int b) {
        return a < b ? a : b;
    }

    static long abs(long x) {
        return x < 0 ? -x : x;
    }

    static long max(long a, long b) {
        return a > b ? a : b;
    }

    static long min(long a, long b) {
        return a < b ? a : b;
    }

    public static void main(String args[]) {
        new Thread(null, new Main(), "Main", 1 << 28).start();
    }

    static boolean OJ = System.getProperty("ONLINE_JUDGE") != null;

    public void console(Object... objects) {
        if (!OJ) {
            out.println(Arrays.deepToString(objects));
            out.flush();
        }
    }

    @SuppressWarnings({"Duplicates", "unused"})
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[2048];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader() {
            this.stream = System.in;
        }

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public InputReader(SpaceCharFilter filter) {
            this.stream = System.in;
            this.filter = filter;
        }

        public InputReader(InputStream stream, SpaceCharFilter filter) {
            this.stream = stream;
            this.filter = filter;
        }

        public int read() {
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public int nextDigit() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return c - '0';
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return negative ? -res : res;
        }

        public int[] nextInts(int N) {
            int[] nums = new int[N];
            for (int i = 0; i < N; i++)
                nums[i] = nextInt();
            return nums;
        }

        public long[] nextLongs(int N) {
            long[] nums = new long[N];
            for (int i = 0; i < N; i++)
                nums[i] = nextLong();
            return nums;
        }

        public int nextUnsignedInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res;
        }

        public final long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return negative ? -res : res;
        }

        public final long nextUnsignedLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 || c == '.'));

            if (c != '.') {
                return res * sgn;
            }
            c = read();

            long aft = 0;
            int len = 1;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                aft *= 10;
                len *= 10;
                aft += c - '0';
                c = read();
            } while (!isSpaceChar(c));

            return res * sgn + aft / (1.0 * len);
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public char[] nextChars() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            char[] chars = new char[res.length()];
            res.getChars(0, chars.length, chars, 0);
            return chars;
        }

        public int[][] nextIntMatrix(int rows, int cols) {
            int[][] matrix = new int[rows][cols];
            for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++)
                    matrix[i][j] = nextInt();
            return matrix;
        }

        public long[][] nextLongMatrix(int rows, int cols) {
            long[][] matrix = new long[rows][cols];
            for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++)
                    matrix[i][j] = nextLong();
            return matrix;
        }

        public char[][] nextCharMap(int rows, int cols) {
            char[][] matrix = new char[rows][cols];
            for (int i = 0; i < rows; i++)
                for (int j = 0; j < cols; j++)
                    matrix[i][j] = nextChar();
            return matrix;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.*;
import java.util.*;

/*
 * And now I wonder if I should delete these comments cause they might throw me off.
 * Lol who cares though?
 */

public class R364C {
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner s = new Scanner(System.in);
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		int n = Integer.parseInt(f.readLine());
		char[] a = f.readLine().toCharArray();
		int difTypes = 0;
		TreeSet<Character> types = new TreeSet<Character>();
		for(int i = 0; i < n; i++) {
			if(!types.contains(a[i])) {
				types.add(a[i]);
			}
		}
		int i = 0, j = 0;
		difTypes = types.size();
		int curTypes = 0;
		int min = Integer.MAX_VALUE;
		TreeSet<Character> has = new TreeSet<Character>();
		HashMap<Character, Integer> freq = new HashMap<Character, Integer>();
		while(i < n && j < n) {
//			System.out.println(i + " " + j);
			has.add(a[j]);
			if(!freq.containsKey(a[j])) {
				freq.put(a[j], 1);
			} else {
				freq.put(a[j], freq.get(a[j])+1);
			}
			j++;
			curTypes = has.size();
			if(curTypes == difTypes) min = Math.min(min, j-i);
//			System.out.println(freq.toString());
//			System.out.println(curTypes);
//			System.out.println();
			while(i < n && has.size() == difTypes) {
				int Freq = freq.get(a[i]);
//				System.out.println(Freq);
				if(Freq - 1 == 0) {
					has.remove(a[i]);
					freq.put(a[i], freq.get(a[i])-1);
					i++;
					break;
				}
				freq.put(a[i], freq.get(a[i])-1);
				i++;
				if(curTypes == difTypes) min = Math.min(min, j-i);
			}
			curTypes = has.size();
		}
//		if(curTypes == difTypes) min = Math.min(min, j-i);
		System.out.println(min);
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class Third{
	static long mod=1000000007;

    public static void main(String[] args) throws Exception{
    	 InputReader in = new InputReader(System.in);
    	PrintWriter pw=new PrintWriter(System.out);

    	//int t=in.readInt();
        //while(t-->0)
        //{

        int n=in.readInt();
    	//long n=in.readLong();
    	/*int a[]=new int[n];
    	for(int i=0;i<n;i++)
    	{
    		a[i]=in.readInt();
    	}*/
    	String a=in.readString();
    	char c[]=a.toCharArray();
    	HashSet<Character>ht=new HashSet<Character>();
    	Deque<Character>q=new LinkedList<Character>();
    	HashSet<Character>hs=new HashSet<Character>();
    	HashMap<Character,Integer>hm=new HashMap<Character,Integer>();
    	for(int i=0;i<n;i++)
    	{
    		ht.add(c[i]);
    	}
    	int t=ht.size();
    	q.addLast(c[0]);
    	hs.add(c[0]);
    	hm.put(c[0],1);
    	int ans=Integer.MAX_VALUE;
    	if(hs.size()==t)
		{
			ans=min(ans,q.size());
		}

    	for(int i=1;i<n;i++)
    	{
    		q.addLast(c[i]);
			hs.add(c[i]);
			if(hm.containsKey(c[i]))
			{
				int x=hm.get(c[i]);
				hm.put(c[i],x+1);
			}
			else
				hm.put(c[i],1);
    		while(hs.size()==t)
    		{
    			ans=min(ans,q.size());
    			char ch=q.peekFirst();
    			int x=hm.get(ch);
    			if(x==1)
    				break;
    			else
    				{
    				hm.put(ch, x-1);
    				q.pollFirst();
    				}

    		}

    	}
		pw.println(ans);

    	//}

    	pw.close();
    }

public static long gcd(long x,long y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}
public static int gcd(int x,int y)
{
	if(x%y==0)
		return y;
	else
		return gcd(y,x%y);
}
public static int abs(int a,int b)
{
	return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
	return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static int min(int a,int b)
{
	if(a>b)
		return b;
	else
		return a;
}
public static long max(long a,long b)
{
	if(a>b)
		return a;
	else
		return b;
}
public static long min(long a,long b)
{
	if(a>b)
		return b;
	else
		return a;
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}
public static long pow(long n,long p)
{
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;

}
static class Pair implements Comparable<Pair>
{
	int a,b;
	Pair (int a,int b)
	{
		this.a=a;
		this.b=b;
	}

	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		if(this.a!=o.a)
		return Integer.compare(this.a,o.a);
		else
			return Integer.compare(this.b, o.b);
		//return 0;
	}
	public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair)o;
            return p.a == a && p.b == b;
        }
        return false;
    }
    public int hashCode() {
        return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
    }

}

static long sort(int a[])
{  int n=a.length;
	int b[]=new int[n];
	return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
 {   long mid=left+(right-left)/2;
	 c= mergeSort(a,b,left,mid);
	 c+=mergeSort(a,b,mid+1,right);
	 c+=merge(a,b,left,mid+1,right); }
	return c;	 }
static long merge(int a[],int  b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]<=a[j]) {b[k++]=a[i++]; }
else	{ b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1)   b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
	a[i] = b[i];  return c;  }

public static int[] radixSort(int[] f)
{
	int[] to = new int[f.length];
	{
		int[] b = new int[65537];
		for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
		for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
		for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
		int[] d = f; f = to;to = d;
	}
	{
		int[] b = new int[65537];
		for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
		for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
		for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
		int[] d = f; f = to;to = d;
	}
	return f;
}
   static  class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

        public int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public double readDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, readInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	//StringBuilder sb=new StringBuilder("");
	 //InputReader in = new InputReader(System.in);
	//PrintWriter pw=new PrintWriter(System.out);
	//String line=br.readLine().trim();

	//int t=Integer.parseInt(br.readLine());
  //	while(t-->0)
  	//{
  	//int n=Integer.parseInt(br.readLine());
	//long n=Long.parseLong(br.readLine());
	//String l[]=br.readLine().split(" ");
  //int m=Integer.parseInt(l[0]);
	//int k=Integer.parseInt(l[1]);
	//String l[]=br.readLine().split(" ");
	//l=br.readLine().split(" ");
	/*int a[]=new int[n];
	for(int i=0;i<n;i++)
	{
		a[i]=Integer.parseInt(l[i]);
	}*/
	   //System.out.println(" ");

	//}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class C364 {
	static HashMap<Character, Integer> freq;
	static int unique = 0;
	public static void main(String[] args) throws Exception {
		FastScanner in = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);

		int n = in.nextInt();
		char[] s = in.next().toCharArray();
		freq = new HashMap<Character, Integer>();
		for(int i = 0; i < n; i++) {
			char c = s[i];
			if(!freq.containsKey(c))
				freq.put(c, 0);
		}

		int k = freq.size();
		int l = 0, r = 0, best = n;
		inc(s[0]);

		while(r < n) {
			if(unique == k) { // got all, move left
				best = Math.min(best, r+1-l);
				dec(s[l++]);
			}
			else { // advance r
				if(++r == n)
					break;
				inc(s[r]);
			}
		}

		pw.println(best);

		pw.flush();
		pw.close();
	}

	static void inc(char c) {
		int cur = freq.get(c);
		if(cur == 0)
			unique++;
		freq.put(c, cur+1);
	}

	static void dec(char c) {
		int cur = freq.get(c);
		if(cur == 1)
			unique--;
		freq.put(c, cur-1);
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer("");
		}

		String next() throws Exception {
			while(!st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		int nextInt() throws Exception {
			return Integer.parseInt(next());
		}
	}
}


import java.io.*;
import java.util.*;

public class C {
	InputStream is;

	int __t__ = 1;
	int __f__ = 0;
	int __FILE_DEBUG_FLAG__ = __f__;
	String __DEBUG_FILE_NAME__ = "src/C4";

	FastScanner in;
	PrintWriter out;

	int charToIndex(char c) {
		if (Character.isLowerCase(c))
			return c - 'a';
		else if (Character.isUpperCase(c))
			return c - 'A' + 26;
		return -1;
	}

	int CH_NUM = 52;
	public void solve() {
		int n = in.nextInt();
		String s = in.next();

		boolean[] exist = new boolean[CH_NUM];
		int typeNum = 0;
		for (int i = 0; i < n; i++) {
			int idx = charToIndex(s.charAt(i));
			if (!exist[idx]) {
				exist[idx] = true;
				typeNum++;
			}
		}

		int get = 0;
		int tail = 0, head = 0;
		int res = Integer.MAX_VALUE;
		int[] cnt = new int[CH_NUM];
		while (tail < n || head < n) {
			if (head == n || typeNum == get) {
				int idx = charToIndex(s.charAt(tail++));
				if (cnt[idx] == 1) get--;
				cnt[idx]--;
			} else {
				int idx = charToIndex(s.charAt(head++));
				if (cnt[idx] == 0) get++;
				cnt[idx]++;
			}
			if (typeNum == get)
				res = Math.min(res, head - tail);
		}
		System.out.println(res);
		/*
		int[] currentRightMost = new int[CH_NUM];
		Arrays.fill(currentRightMost, -1);
		int[][] next = new int[n+1][CH_NUM];
		for (int i = 0; i < n + 1; i++) {
			Arrays.fill(next[i], 1 << 30);
		}
		for (int i = 0; i < n; i++) {
			int idx = charToIndex(s.charAt(i));
			for (int j = 0; j < CH_NUM; j++) if (exist[j]) {
				if (currentRightMost[j] != -1)
					next[currentRightMost[j]][idx] = Math.min(next[currentRightMost[j]][idx], i);
			}
			currentRightMost[idx] = i;
		}

		int res = Integer.MAX_VALUE;
		for (int leftMost = 0; leftMost < n; leftMost++) {
			int maxRightMost = 0;
			int idx = charToIndex(s.charAt(leftMost));
			for (int j = 0; j < CH_NUM; j++) if (exist[j]) {
				if (j != idx)
					maxRightMost = Math.max(maxRightMost, next[leftMost][j]);
			}
			res = Math.min(res, maxRightMost - leftMost + 1);
		}
		System.out.println(res);
		*/
	}

	public void run() {
		if (__FILE_DEBUG_FLAG__ == __t__) {
			try {
				is = new FileInputStream(__DEBUG_FILE_NAME__);
			} catch (FileNotFoundException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			System.out.println("FILE_INPUT!");
		} else {
			is = System.in;
		}
		in = new FastScanner(is);
		out = new PrintWriter(System.out);

		solve();
	}

	public static void main(String[] args) {
		new C().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		int[] nextIntArray(int n, int margin) {
			int[] array = new int[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		long[] nextLongArray(int n, int margin) {
			long[] array = new long[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			return nextDoubleArray(n, 0);
		}

		double[] nextDoubleArray(int n, int margin) {
			double[] array = new double[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}


/**
 * Created by Omar on 7/22/2016.
 */

import java.util.*;
import java.io.*;

public class CF364C {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        String input=br.readLine();
        Set<Character> set = new HashSet<Character>();
        for(int i=0;i<input.length();i++){
            set.add(input.charAt(i));
        }
        StringBuilder sb= new StringBuilder();
for(char x:set){
    sb.append(x);
}
        String substring1=sb.toString();
//        //System.out.println(substring1);
//        int[] count= new int[52];
//        int[] b= new int[52];
//
//        char k;
//        for(int i=0;i<substring1.length();i++){
//            k=substring1.charAt(i);
//            //System.out.println((int)'a');
//            count[(k-'A')]++;
//
//        }
//        for(int i=0;i<52;i++){
//          b[i]=count[i];
//
//            //System.out.println("count "+count[i]);
//        }
//        int answer=set.size();
//
//
//        for(int i=0;i<input.length();i++){
//
//        }
//        System.out.println(answer);
//
        //System.out.println("WAIT");
        System.out.println(solve(input,substring1).length());
        pw.close();
        br.close();
    }
    public static boolean isEmpty(int[] a){
        for(int i=0;i<a.length;i++){
            if(a[i]!=0){
                return false;
            }

        }

return true;
    }
    public static String solve(String S, String T) {
        HashMap<Character, Integer> D = new HashMap<>();
        HashMap<Character, Integer> GET = new HashMap<>();
        int B,E;
        for (int i=0; i<T.length();i++) {
            char c=T.charAt(i);
            if (!D.containsKey(c))
            {
                D.put(c, 1);
            }
            else
            {
                D.put(c, D.get(c) + 1);
            }
        }
        int ccc = 0;
       B=0; E=0;
        int min = Integer.MAX_VALUE;
        // int max = Integer.MIN_VALUE;

        String RESULT = "";
        while (E < S.length()) {

            char c = S.charAt(E);

            if (D.containsKey(c)) {

                if (GET.containsKey(c)) {

                    if (GET.get(c) < D.get(c))
                        ccc++;
                    //ccc--
                    GET.put(c, GET.get(c) + 1);
                } else {

                    GET.put(c, 1);

                    ccc++;
                    //ccc--
                }
            }
            if (ccc == T.length()) {
               // if (ccc != B.length()) {
                char test = S.charAt(B);
                while (!GET.containsKey(test) ||
                        GET.get(test) > D.get(test)) {

                    if (GET.containsKey(test)
                            && GET.get(test) >
                            D.get(test))
                       // GET.put(test, GET.get(test) - 24);

                    GET.put(test, GET.get(test) - 1);
                    //B-=B;
                    B++;

                    test = S.charAt(B);
                    //test += S.charAt(B);

                }
                if (E - B + 1 < min) {
                    RESULT = S.substring(B, E + 1);
                    min = E - B + 1;
                }
                //}
            }
            E++;
        }
        //if(E==0)
        return RESULT;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Ran Bi (ran.bi@addepar.com)
 */
public class C {

  public static void main(String[] arg) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.valueOf(in.readLine());
    char[] s = in.readLine().toCharArray();
    int i = 0, j = 0;
    int[] ct = new int[256];
    Set<Character> all = new HashSet<>();
    for (char c : s) {
      all.add(c);
    }
    int total = 0, res = Integer.MAX_VALUE;
    while (j < s.length) {
      while (total < all.size() && j < s.length) {
        if (ct[s[j]] == 0) {
          total++;
        }
        ct[s[j]]++;
        j++;
      }
      res = Math.min(res, j - i);
      while (total == all.size() && i < s.length) {
        ct[s[i]]--;
        if (ct[s[i]] == 0) {
          total--;
        }
        i++;
        if (total == all.size()) {
          res = Math.min(res, j - i);
        }
      }
    }
    System.out.println(res);
  }
}


import java.io.*;
import java.util.*;
public final class round_364_c
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		int n=sc.nextInt();char[] arr=sc.next().toCharArray();int[] sum=new int[123];int[][] pre=new int[123][n+1];
		char[] a=new char[n+1];
		for(int i=1;i<=n;i++)
		{
			a[i]=arr[i-1];
		}
		boolean[] v=new boolean[123];
		for(int i=1;i<=n;i++)
		{
			sum[a[i]]++;v[a[i]]=true;
			for(int j=65;j<=90;j++)
			{
				pre[j][i]=sum[j];
			}
			for(int j=97;j<=122;j++)
			{
				pre[j][i]=sum[j];
			}
		}
		long min=Integer.MAX_VALUE;
		for(int i=1;i<=n;i++)
		{
			int low=0,high=n-i+1;boolean got=false;
			while(low<high)
			{
				int mid=(low+high)>>1;
				boolean curr=true;
				for(int j=65;j<=90;j++)
				{
					if(v[j])
					{
						if(pre[j][i+mid]-pre[j][i-1]<=0)
						{
							curr=false;
							break;
						}
					}
				}
				for(int j=97;j<=122;j++)
				{
					if(v[j])
					{
						if(pre[j][i+mid]-pre[j][i-1]<=0)
						{
							curr=false;
							break;
						}
					}
				}
				if(curr)
				{
					got=true;
					high=mid;
				}
				else
				{
					low=mid+1;
				}
			}
			if(got)
			{
				min=Math.min(min,(i+low)-i+1);
			}
		}
		out.println(min);
		out.close();
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.awt.Point;
import java.io.*;
import java.lang.Integer;
import java.math.BigInteger;
import java.util.*;

public class Main {

    final boolean ONLINE_JUDGE = !new File("input.txt").exists();
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class LOL implements Comparable<LOL> {
        int x;
        int y;

        public LOL(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(LOL o) {

            if (o.x != x)
                return (int) (o.x - x); // ---->
            return (int) (y - o.y); // <----
        }

    }

    long modulo = 1000 * 1000 * 1000 + 7;
    long binPow (long a, long b) {
        if(b == 0) return 1;
        long c = binPow(a, b / 2);
        long ans = (c * c) % modulo;
        if(b % 2 == 1) ans = (ans * a) % modulo;
        return ans;
    }

    int[] gcd (int a, int b) {
        int[] res = new int[3];
        if (a == 0) {
            res[0] = b; res[1] = 0; res[2] = -1;
            return res;
        }
        res = gcd (b%a, a);
        int x = -(res[2] + (b / a) * res[1]);
        int y = - res[1];
        res[1] = x;
        res[2] = y;
        return res;
    }

    public void solve() throws IOException {
        int n = readInt();
        HashMap<Character,Integer> mapa = new HashMap<>();

        char[] s = readString().toCharArray();

        for(int i = 0; i < n; i++) {
            if(mapa.containsKey(s[i])) {
                int x = mapa.get(s[i]);
                mapa.replace(s[i], x + 1);
            }
            else mapa.put(s[i], 1);
        }

        int sz = mapa.size();
        mapa = new HashMap<>();
        int i = 0;
        while (mapa.size() < sz) {
            if(mapa.containsKey(s[i])) {
                int x = mapa.get(s[i]);
                mapa.replace(s[i], x + 1);
            }
            else mapa.put(s[i], 1);
            i++;
        }
        int ans = i;

        int left = 0;
        int right = i - 1;

        while(right < n) {
            while(left < right) {
                int y = mapa.get(s[left]);
                if(y == 1) mapa.remove(s[left]);
                else mapa.replace(s[left], y - 1);
                if(mapa.size() == sz) {
                    ans = Math.min(ans, right - left);
                    left++;
                }
                else {
                    left++;
                    break;
                }
            }

            right++;
            if(right < n) {
                if (mapa.containsKey(s[right])) {
                    int x = mapa.get(s[right]);
                    mapa.replace(s[right], x + 1);
                } else mapa.put(s[right], 1);
            }

        }

        out.print(ans);

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class C364C {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	static int n;
	static int[] a;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		n = nextInt();
		int ans = n, cc, cur = 0;
		a = new int [52];
		char[] c = next().toCharArray();
		int l = 0, len = 0;
		for (int i = 0; i < n; ++i) {
			if (Character.isUpperCase(c[i])) {
				cur = 26 + c[i] - 'A';
			} else
				cur = c[i] - 'a';
			if (a[cur] == 0) {
				a[cur]++;
				len++;
				ans = i - l + 1;
			} else {
				a[cur]++;
				for (; l < i; ++l) {
					if (Character.isUpperCase(c[l])) {
						cc = 26 + c[l] - 'A';
					} else
						cc = c[l] - 'a';

					if (a[cc] > 1) {
						--a[cc];
					} else break;
				}
				if (i - l + 1 < ans) {
					ans = i - l + 1;
				}
			}
		}

		/*int l = 0, r = n - 1;
		for (l = 0; l < n; ++l) {
			if (Character.isUpperCase(c[l])) {
				if (a[26 + c[l] - 'A'] > 1) {
					a[26 + c[l] - 'A']--;
				} else break;
			} else {
				if (a[c[l] - 'a'] > 1) {
					a[c[l] - 'a']--;
				} else break;

			}
		}
		for (r = n - 1; r >= 0; --r) {
			if (Character.isUpperCase(c[r])) {
				if (a[26 + c[r] - 'A'] > 1) {
					a[26 + c[r] - 'A']--;
				} else break;
			} else {
				if (a[c[r] - 'a'] > 1) {
					a[c[r] - 'a']--;
				} else break;

			}
		}*/
		pw.print(ans);
		pw.close();
	}

	private static int sumf(int[] fen, int id) {
		int summ = 0;
		for (; id >= 0; id = (id & (id + 1)) - 1)
 			summ += fen[id];
		return summ;
	}

	private static void addf(int[] fen, int id) {
		for (; id < fen.length; id |= id + 1)
			fen[id]++;
	}

	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class A {

	static double eps=(double)1e-15;
	static long mod=(int)1e9+7;
	public static void main(String args[]){
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code----------
		int n=in.nextInt();
		int l=0,r=0;
		String s=in.nextLine();
		HashSet<Character> size=new HashSet<>();
		for(int i=0;i<n;i++){
			char p=s.charAt(i);
			size.add(p);
		}
		int chk=size.size();
		HashMap<Character, Integer> hm=new HashMap<>();
		int ans=Integer.MAX_VALUE;
		while(l<n){
			if(hm.size()<chk && r<n){
				char p=s.charAt(r);
				if(hm.containsKey(p)){
					hm.put(p, hm.get(p)+1);
				}
				else{
					hm.put(p, 1);
				}
				r++;
			}
			else{
				char p=s.charAt(l);
				if(hm.get(p)==1){
					hm.remove(p);
				}
				else{
					hm.put(p, hm.get(p)-1);
				}
				l++;
			}
			if(hm.size()==chk){
				ans=Math.min(ans, r-l);
			}
		}
		out.println(ans);
		out.close();
		//---------------The End------------------

	}
	static class Pair implements Comparable<Pair> {
		int u;
		int v;

		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner in=new Scanner(new BufferedInputStream(System.in));
	int n=in.nextInt();
	char b[]=in.next().toCharArray();
	int bb[]=new int [b.length];

	int Mark[]=new int [26*2+1];
	int Mark1[]=new int [26*2+1];

	int ans=0;
	for(int i=0;i<b.length;i++){
		char f=b[i];
		int a;
		if(f>='a'&&f<='z')
			a=f-'a';
		else  a=f-'A'+26;
		bb[i]=a;
		if(Mark1[a] == 0){
			ans++;
			Mark1[a]=1;}

}
//	System.out.println(ans);
	int i;
    // int L ,R ,nowsum ,Ans;
   int  L = 0 ,nowsum = 0 ,Ans = n,R = 0;
     //找到LR
     for(i = 0 ;i < n ;i ++)
     {
         if(Mark[bb[i]]==0) nowsum ++;
           Mark[bb[i]] ++;
           if(nowsum == ans)
           {
              R = i;
              break;
           }

     }
//     System.out.println("r"+R);
     Ans = R - L + 1;
     for(i = L ;i < n ;i ++)
     {

        if((--Mark[bb[i]])==0)
        {
           int ok = 0;
           for(int j = R + 1 ;j < n ;j ++)
           {

                 Mark[bb[j]] ++;
                 if(bb[j] == bb[i])
                 {
                    ok = 1;
                    R = j;
                    break;
                 }

           }
           if(ok==0) break;
        }
        if(Ans > R - i) Ans = R - i;
     }
    	 System.out.println(Ans);

	}

}


//package baobab;

import java.io.*;
import java.util.*;

public class C {

    public static void main(String[] args) {
        CIO io = new CIO();
        try {
            Csolver solver = new Csolver(io);
            solver.solve();
        } finally {
            io.close();
        }
    }

}

class Csolver {
    CIO io;

    public Csolver(CIO io) {
        this.io = io;
    }

    public void solve() {
        int n = io.nextInt();
        String input = io.next();
        int[] count = new int[1000];
        int pokemonsInRange = 0;
        int answer = Integer.MAX_VALUE;
        int a = 0;
        int b = 0;
        for (; b < n ; b++) {
            char end = input.charAt(b);
            if (count[end] == 0) {
                pokemonsInRange++;
                answer = Integer.MAX_VALUE;
            }
            count[end]++;
            while (count[input.charAt(a)] > 1) {
                count[input.charAt(a)]--;
                a++;
            }
            answer = Math.min(answer, b-a+1);
        }
        io.println(answer);
    }

    private static class Pair implements Comparable<Pair> {
        int id;
        long val;

        public Pair(long val, int id) {
            this.val = val;
            this.id = id;
        }

        @Override
        public int compareTo(Pair o) {
            if (this.val < o.val) return -1;
            if (this.val > o.val) return 1;
            return this.id - o.id;
        }
    }

    private List<Integer>[] toGraph(CIO io, int n) {
        List<Integer>[] g = new ArrayList[n+1];
        for (int i=1; i<=n; i++) g[i] = new ArrayList<>();
        for (int i=1; i<=n-1; i++) {
            int a = io.nextInt();
            int b = io.nextInt();
            g[a].add(b);
            g[b].add(a);
        }
        return g;
    }
}

class CIO extends PrintWriter {
    private InputStreamReader r;
    private static final int BUFSIZE = 1 << 15;
    private char[] buf;
    private int bufc;
    private int bufi;
    private StringBuilder sb;

    public CIO() {
        super(new BufferedOutputStream(System.out));
        r = new InputStreamReader(System.in);

        buf = new char[BUFSIZE];
        bufc = 0;
        bufi = 0;
        sb = new StringBuilder();
    }

    private void fillBuf() throws IOException {
        bufi = 0;
        bufc = 0;
        while(bufc == 0) {
            bufc = r.read(buf, 0, BUFSIZE);
            if(bufc == -1) {
                bufc = 0;
                return;
            }
        }
    }

    private boolean pumpBuf() throws IOException {
        if(bufi == bufc) {
            fillBuf();
        }
        return bufc != 0;
    }

    private boolean isDelimiter(char c) {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
    }

    private void eatDelimiters() throws IOException {
        while(true) {
            if(bufi == bufc) {
                fillBuf();
                if(bufc == 0) throw new RuntimeException("IO: Out of input.");
            }

            if(!isDelimiter(buf[bufi])) break;
            ++bufi;
        }
    }

    public String next() {
        try {
            sb.setLength(0);

            eatDelimiters();
            int start = bufi;

            while(true) {
                if(bufi == bufc) {
                    sb.append(buf, start, bufi - start);
                    fillBuf();
                    start = 0;
                    if(bufc == 0) break;
                }

                if(isDelimiter(buf[bufi])) break;
                ++bufi;
            }

            sb.append(buf, start, bufi - start);

            return sb.toString();
        } catch(IOException e) {
            throw new RuntimeException("IO.next: Caught IOException.");
        }
    }

    public int nextInt() {
        try {
            int ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
                    ret *= 10;
                    ret -= (int)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
                } else {
                    throw new RuntimeException("IO.nextInt: Invalid int.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextInt: Caught IOException.");
        }
    }

    public long nextLong() {
        try {
            long ret = 0;

            eatDelimiters();

            boolean positive = true;
            if(buf[bufi] == '-') {
                ++bufi;
                if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
                positive = false;
            }

            boolean first = true;
            while(true) {
                if(!pumpBuf()) break;
                if(isDelimiter(buf[bufi])) {
                    if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
                    break;
                }
                first = false;

                if(buf[bufi] >= '0' && buf[bufi] <= '9') {
                    if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
                    ret *= 10;
                    ret -= (long)(buf[bufi] - '0');
                    if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
                } else {
                    throw new RuntimeException("IO.nextLong: Invalid long.");
                }

                ++bufi;
            }

            if(positive) {
                if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
                ret = -ret;
            }

            return ret;
        } catch(IOException e) {
            throw new RuntimeException("IO.nextLong: Caught IOException.");
        }
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class theyareeverywhere {

    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter w = new PrintWriter(System.out);

        //SWEEP LINE BABYY

        int n = Integer.parseInt(r.readLine());

        char[] pokemans = r.readLine().toCharArray();

        int[] counts = new int[52];
        boolean[] exists = new boolean[52];

        for (int i = 0; i < pokemans.length; i++) {
            exists[index(pokemans[i])] = true;
        }

        int left = 0, right = 0;
        counts[index(pokemans[0])] = 1;

        int answer = 1000000000;

        while (left < n && right < n) {
            if (!valid(counts, exists)) {
                //move right
                right++;
                if (right < n)
                counts[index(pokemans[right])]++;
            } else {
                answer = Math.min(answer, right - left + 1);
                left++;
                if (left - 1 >= 0)
                counts[index(pokemans[left - 1])]--;
            }
        }

        w.println(answer);
        w.flush();
    }

    public static boolean valid(int[] counts, boolean[] exists) {
        for (int i = 0; i < counts.length; i++) {
            if (exists[i] && counts[i] == 0) return false;
        }
        return true;
    }

    public static int index(char c) {
        if (c >= 'a' && c <= 'z') {
            return c - 'a';
        } else {
            return c - 'A' + 26;
        }
    }

}


/**
 * Created by ankeet on 7/22/16.
 */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C701 {

    static FastReader in = null;
    static PrintWriter out = null;

    public static void solve()
    {
        int n = in.nint();
        String pk = in.next();
        boolean[] occ = new boolean[52];
        for(int i=0; i<n; i++)
        {
            char c = pk.charAt(i);
            int val = Character.isUpperCase(c)?  (int)(c-'A') : (int)(c-'a'+26);
            occ[val] = true;
        }
        int[][] next = new int[n][52];
        for(int i=0; i<n; i++) for(int j=0; j<52; j++) next[i][j] = -1;

        for(int i= n-1; i>=0; i--) {

            char c = pk.charAt(i);
            int val = Character.isUpperCase(c)?  (int)(c-'A') : (int)(c-'a'+26);
            next[i][val] = i;
            if(i<n-1)
            for(int j=0; j<52; j++)
            {
                if(j!=val)
                {
                    next[i][j] = next[i+1][j];
                }
            }

        }

        int min = Integer.MAX_VALUE;
        for(int i=0; i<n; i++)
        {
            int maxd = 0;
            boolean endearly = false;
            for(int j=0; j<52; j++)
            {
                if(occ[j] && next[i][j] == -1)
                {
                    endearly = true;
                    break;
                }
                else if(occ[j])
                {
                    maxd = Math.max(maxd, next[i][j]-i+1);
                }
            }

            if(endearly) break;
            min = Math.min(min, maxd);
        }

        out.println(min);

    }

    public static void main(String[] args)
    {
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try{
                    tokenizer = new StringTokenizer(read.readLine());
                }catch(Exception e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nint()
        {
            return Integer.parseInt(next());
        }
        public long nlong()
        {
            return Long.parseLong(next());
        }
        public double ndouble()
        {
            return Double.parseDouble(next());
        }

        public int[] narr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nint();
            }
            return a;
        }

        public long[] nlarr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nlong();
            }
            return a;
        }
    }

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;

public class Main
{
    /********************************************** a list of common variables **********************************************/
    private MyScanner scan = new MyScanner();
    private PrintWriter out = new PrintWriter(System.out);
    private final double PI = Math.PI;
    private final int INF = (int)(1e9);
    private final double EPS = 1e-6;
    private final int SIZEN = (int)(1e7);
    private final int MOD = (int)(1e9 + 7);
    private final long MODH = 10000000007L, BASE = 10007;
    private final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};
    int n;
    int[] sum;
    int[][] a;

    public void foo1() {
        int n = scan.nextInt();
        int sum = 0;
        int[] a = new int[n];
        for (int i = 0;i < n;++i) {
            a[i] = scan.nextInt();
            sum += a[i];
        }
        int avg = sum * 2 / n;
        for (int i = 0;i < n;++i) {
            if (a[i] == 0) {
                continue;
            }
            for (int j = i + 1;j < n;++j) {
                if (a[i] + a[j] == avg) {
                    a[j] = 0;
                    System.out.println((i + 1) + " " + (j + 1));
                    break;
                }
            }
        }
    }

    public void foo2() {
        int n = scan.nextInt();
        int m = scan.nextInt();
        HashSet<Integer> row = new HashSet<Integer>();
        HashSet<Integer> col = new HashSet<Integer>();
        for (int i = 0;i < m;++i) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            row.add(x);
            col.add(y);
            out.print((long) (n - row.size()) * (n - col.size()) + " ");
        }
    }

    public int getId(char c) {
        return (c >= 'a' && c <= 'z') ? c - 'a': c - 'A' + 26;
    }

    public boolean isOk(int len) {
        for (int i = 0;i + len <= n;++i) {
            boolean flag = true;
            for (int j = 0;j < 52;++j) {
                if (a[i + len][j] - a[i][j] == 0 && sum[j] != 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                return true;
            }
        }
        return false;
    }

    public void foo() {
        n = scan.nextInt();
        char[] s = scan.next().toCharArray();
        a = new int[n + 1][52];
        sum = new int[52];
        for (int i = 0;i < n;++i) {
            for (int j = 0;j < 52;++j) a[i + 1][j] = a[i][j];
            ++a[i + 1][getId(s[i])];
            ++sum[getId(s[i])];
        }
        int left = 1, right = n, ans = n;
        while (left <= right) {
            int mid = (left + right) >> 1;
            if (isOk(mid)) {
                ans = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        out.println(ans);
    }

    public static void main(String[] args)
    {
        Main m = new Main();
        m.foo();
        m.out.close();
    }

    /********************************************** a list of common algorithms **********************************************/
    /**
     * 1---Get greatest common divisor
     * @param a :	first number
     * @param b :	second number
     * @return		greatest common divisor
     */
    public long gcd(long a, long b)
    {
        return 0 == b ? a : gcd(b, a % b);
    }

    /**
     * 2---Get the distance from a point to a line
     * @param x1	the x coordinate of one endpoint of the line
     * @param y1	the y coordinate of one endpoint of the line
     * @param x2	the x coordinate of the other endpoint of the line
     * @param y2	the y coordinate of the other endpoint of the line
     * @param x		the x coordinate of the point
     * @param y		the x coordinate of the point
     * @return		the distance from a point to a line
     */
    public double getDist(long x1, long y1, long x2, long y2, long x, long y)
    {
        long a = y2 - y1;
        long b = x1 - x2;
        long c = y1 * (x2 - x1) - x1 * (y2 - y1);
        return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
    }

    /**
     * 3---Get the distance from one point to a segment (not a line)
     * @param x1	the x coordinate of one endpoint of the segment
     * @param y1	the y coordinate of one endpoint of the segment
     * @param x2	the x coordinate of the other endpoint of the segment
     * @param y2	the y coordinate of the other endpoint of the segment
     * @param x		the x coordinate of the point
     * @param y		the y coordinate of the point
     * @return		the distance from one point to a segment (not a line)
     */
    public double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)
    {
        double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
        if(cross <= 0)
        {
            return (x - x1) * (x - x1) + (y - y1) * (y - y1);
        }
        double d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
        if(cross >= d)
        {
            return (x - x2) * (x - x2) + (y - y2) * (y - y2);
        }
        double r = cross / d;
        double px = x1 + (x2 - x1) * r;
        double py = y1 + (y2 - y1) * r;
        return (x - px) * (x - px) + (y - py) * (y - py);
    }

    /**
     * 4---KMP match, i.e. kmpMatch("abcd", "bcd") = 1, kmpMatch("abcd", "bfcd") = -1.
     * @param t:	String to match.
     * @param p:	String to be matched.
     * @return		if can match, first index; otherwise -1.
     */
    public int kmpMatch(char[] t, char[] p)
    {
        int n = t.length;
        int m = p.length;
        int[] next = new int[m + 1];
        next[0] = -1;
        int j = -1;
        for(int i = 1;i < m;++i)
        {
            while(j >= 0 && p[i] != p[j + 1])
            {
                j = next[j];
            }
            if(p[i] == p[j + 1])
            {
                ++j;
            }
            next[i] = j;
        }
        j = -1;
        for(int i = 0;i < n;++i)
        {
            while(j >= 0 && t[i] != p[j + 1])
            {
                j = next[j];
            }
            if(t[i] == p[j + 1])
            {
                ++j;
            }
            if(j == m - 1)
            {
                return i - m + 1;
            }
        }
        return -1;
    }

    /**
     * 5---Get the hash code of a String
     * @param	s:	input string
     * @return	hash code
     */
    public long hash(String s)
    {
        long key = 0, t = 1;
        for(int i = 0;i < s.length();++i)
        {
            key = (key + s.charAt(i) * t) % MODH;
            t = t * BASE % MODH;
        }
        return key;
    }

    /**
     * 6---Get x ^ n % MOD quickly.
     * @param	x:	base
     * @param 	n:	times
     * @return	x ^ n % MOD
     */
    public long quickMod(long x, long n)
    {
        long ans = 1;
        while(n > 0)
        {
            if(1 == n % 2)
            {
                ans = ans * x % MOD;
            }
            x = x * x % MOD;
            n >>= 1;
        }
        return ans;
    }

    /**
     * 7---judge if a point is located inside a polygon
     * @param x0	the x coordinate of the point
     * @param y0	the y coordinate of the point
     * @return true if it is inside the polygon, otherwise false
     */
	/*public boolean contains(double x0, double y0)
	{
		int cross = 0;
		for(int i = 0;i < n;++i)
		{
			double s = x[i + 1] == x[i] ? 100000000 : (double)(y[i + 1] - y[i]) / (x[i + 1] - x[i]);
			boolean b1 = x[i] <= x0 && x0 < x[i + 1];
			boolean b2 = x[i + 1] <= x0 && x0 < x[i];
			boolean b3 = y0 < s * (x0 - x[i]) + y[i];
			if((b1 || b2) && b3) ++cross;
		}
		return cross % 2 != 0;
	}*/

    /**
     * 8---judge if a point is located on the segment
     * @param	x1	the x coordinate of one point of the segment
     * @param	y1	the y coordinate of one point of the segment
     * @param 	x2	the x coordinate of another point of the segment
     * @param 	y2	the y coordinate of another point of the segment
     * @param	x	the x coordinate of the point
     * @param 	y	the y coordinate of the point
     * @return	true if it is located on the segment, otherwise false
     */
    public boolean isOnSeg(long x1, long y1, long x2, long y2, long x, long y)
    {
        return (x - x1) * (y2 - y1) == (x2 - x1) * (y - y1) &&
                x >= Math.min(x1, x2) && x <= Math.max(x1, x2) &&
                y >= Math.min(y1, y2) && y <= Math.max(y1, y2);
    }

    /**
     * 9---get the cross product
     * @param 	p1	point A
     * @param 	p2	point B
     * @param 	p	point O
     * @return	cross product of OA x OB
     */
	/*public long cross(Point p1, Point p2, Point p)
	{
		return (long)(p1.x - p.x) * (p2.y - p.y) - (long)(p2.x - p.x) * (p1.y - p.y);
	}*/

    /**
     * 10---implement topsort and tell if it is possible
     * @return true if it is possible to implement topsort, otherwise false
     */
	/*public boolean topsort()
	{
		Queue<Integer> q = new LinkedList<Integer>();
		StringBuilder ans = new StringBuilder();
		int[] in = new int[26];
		for(int i = 0;i < 26;++i)
		{
			if(0 == in[i])
			{
				ans.append((char)('a' + i));
				q.add(i);
			}
		}
		while(!q.isEmpty())
		{
			int u = q.poll();
			for(int i = 0;i < 26;++i)
			{
				if(map[u][i])
				{
					--in[i];
					if(0 == in[i])
					{
						ans.append((char)('a' + i));
						q.add(i);
					}
				}
			}
		}
		return 26 == ans.length();
	}*/

    class MyScanner
    {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        BufferedInputStream bis = new BufferedInputStream(System.in);

        public int read()
        {
            if (-1 == numChars)
            {
                throw new InputMismatchException();
            }
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = bis.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do
            {
                if (c < '0' || c > '9')
                {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9')
                {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c & 15;
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                    {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9')
                    {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c & 15) * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String next()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c)
        {
            return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
        }
    }
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dr = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dc = {0, 1, 0, -1, 1, 1, -1, -1};

    public static void main(String[] args) throws Exception{
        int N = Integer.parseInt(br.readLine());
        char[] A = br.readLine().toCharArray();

        HashSet<Character> cndD = new HashSet<Character>();
        for(int i = 0; i < N; i++){
            cndD.add(A[i]);
        }

        int cnt = cndD.size();

        int a = 0;
        int b = 0;

        int ans = (1 << 30);
        HashMap<Character, Integer> d = new HashMap<Character, Integer>();
        while(b < N){
            if(d.containsKey(A[b])){
                if(A[a] == A[b]){
                    a++;
                    while(d.get(A[a]) > 1){
                        d.put(A[a], d.get(A[a])-1);
                        a++;
                    }
                } else{
                    d.put(A[b], d.get(A[b])+1);
                }
            } else{
                d.put(A[b], 1);
            }
            if(d.size() == cnt){
                ans = Math.min(b-a+1, ans);
            }
            b++;
        }

        pw.print(ans + "\n");
        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int a, b;

    Pair(int a, int b){
        this.a = a;
        this.b = b;
    }

    @Override
    public int compareTo(Pair P){
        if(P.b != this.b){
            return b - P.b;
        } else if(P.a == this.a){
            return a - P.a;
        } else{
            return 0;
        }
    }

    public String toString(){
        return a + " " + b;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] poks = in.next().toCharArray();
            boolean[] was = new boolean[52];
            for (int i = 0; i < n; i++) {
                if (Character.isLowerCase(poks[i])) {
                    was[poks[i] - 'a'] = true;
                } else {
                    was[poks[i] - 'A' + 26] = true;
                }
            }
            int count = 0;
            for (int i = 0; i < 52; i++) {
                count += was[i] ? 1 : 0;
            }
            int[] vis = new int[52];
            int pre = 0;
            int chr = 0;
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int pos = poks[i] - 'a';
                if (Character.isUpperCase(poks[i])) {
                    pos = poks[i] - 'A' + 26;
                }

                if (vis[pos] == 0) {
                    chr++;
                }
                vis[pos]++;
                while (chr == count) {
                    ans = Math.min(ans, i - pre + 1);
                    pos = poks[pre] - 'a';
                    if (Character.isUpperCase(poks[pre])) {
                        pos = poks[pre] - 'A' + 26;
                    }
                    vis[pos]--;
                    if (vis[pos] == 0) chr--;
                    pre++;
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * Created by pallavi on 22/7/16.
 */
public class C701 {
    public static int f(char c) {
        if (c >= 'a' && c <= 'z') {
            return c - 'a';
        } else {
            return 26 + c - 'A';
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(reader.readLine());
        char[] ch = reader.readLine().toCharArray();

        LinkedList<Integer>[] p = new LinkedList[52];

        for (int i = 0; i < 52; i++) {
            p[i] = new LinkedList<>();
        }

        int[] fc = new int[n];

        for (int i = 0; i < n; i++) {
            int cc = f(ch[i]);
            p[cc].add(i);
            fc[i] = cc;
        }
        int en = 0;
        for (int i = 0; i < 52; i++) {
            if (p[i].size() > 0) en = Math.max(en, p[i].poll());
        }

        int mx = en + 1;

        for (int i = 0; i < n; i++) {
            if (p[fc[i]].size() == 0) break;
            en = Math.max(en, p[fc[i]].poll());
            mx = Math.min(mx, en - i);
        }

        System.out.println(mx);
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		char[]a = next().toCharArray();
		int[]cnt = new int[256];
		for (int i = 0; i < n; i++) {
			cnt[a[i]]++;
		}
		int alldiff = 0;
		for (int i = 0; i < 256; i++) {
			if (cnt[i] > 0)
				alldiff++;
		}
		Arrays.fill(cnt, 0);
		int diff = 0, right = -1, ans = n+5;
		for (int i = 0; i < n; i++) {
			if (right < i) {
				cnt[a[i]]++;
				diff = 1;
				right = i;
			}
			while (right < n-1 && diff < alldiff) {
				right++;
				cnt[a[right]]++;
				if (cnt[a[right]]==1)
					diff++;
			}
			if (diff==alldiff && right-i+1 < ans) {
				ans = right-i+1;
			}
			cnt[a[i]]--;
			if (cnt[a[i]]==0)
				diff--;
		}
		System.out.println(ans);
		pw.close();
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    public void solve() {
        int n = in.nextInt();
        TreeMap<Character, Integer> map = new TreeMap<>();
        ArrayList<Integer> list = new ArrayList<>();
        String s = in.next();
        for (int i = 0; i < n; i++) {
            char ch = s.charAt(i);
            if (!map.containsKey(ch))
                map.put(ch, map.size());
            list.add(map.get(ch));
        }

        int l = 0;
        int ans = Integer.MAX_VALUE;
        int nad = map.size();
        int cnt[] = new int[n];

        for (int i = 0; i < list.size(); i++) {
            if (cnt[list.get(i)] == 0)
                nad--;
            cnt[list.get(i)]++;

            if (nad == 0) {
                ans = min(ans, i - l + 1);
                while (true) {
                    if (cnt[list.get(l)] == 1) {
                        ans = min(ans, i - l + 1);
                        cnt[list.get(l)]--;
                        l++;
                        nad++;
                        break;
                    } else {
                        cnt[list.get(l)]--;
                        l++;
                    }
                }
            }
        }

        out.print(ans);
    }

    public void run() {
        if (FILE.equals("")) {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        } else {
            try {
                in = new FastScanner(new FileInputStream(FILE +
                        ".in"));
                out = new PrintWriter(new FileOutputStream(FILE +
                        ".out"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        solve();
        out.close();
    }

    public static void main(String[] args) {
        (new Main()).run();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }
    }

    class Pair<A extends Comparable<A>, B extends Comparable<B>>
            implements Comparable<Pair<A, B>> {
        public A a;
        public B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Pair<A, B> o) {
            if (o == null || o.getClass() != getClass())
                return 1;
            int cmp = a.compareTo(o.a);
            if (cmp == 0)
                return b.compareTo(o.b);
            return cmp;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (a != null ? !a.equals(pair.a) : pair.a != null) return
                    false;
            return !(b != null ? !b.equals(pair.b) : pair.b != null);
        }
    }

    class PairInt extends Pair<Integer, Integer> {
        public PairInt(Integer u, Integer v) {
            super(u, v);
        }
    }

    class PairLong extends Pair<Long, Long> {
        public PairLong(Long u, Long v) {
            super(u, v);
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class TheyAreEverywhere {
    static StringTokenizer st;
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in), 325678);
    static int[] id = new int[100000];

    public static void main(String[] args) throws IOException {
        int n = in();
        String s = next();
        int total = 0;
        int[] seq = new int[n];
        boolean[] c = new boolean[100000];
        for (int i = 0; i < n; i++) {
            seq[i] = s.charAt(i);
            if (!c[seq[i]]) {
                total++;
                c[seq[i]] = true;
            }
        }

        Arrays.fill(id, -1);
        int best = Integer.MAX_VALUE;
        TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return id[o1] - id[o2];
            }
        });
        for (int i = 0; i < n; i++) {
            q.remove(seq[i]);
            id[seq[i]] = i;
            q.add(seq[i]);
            if (q.size() == total) {
                //System.out.println("best: i=" + i + " id=" + id[q.first()]);
                best = Math.min(best, i - id[q.first()] + 1);
            }
            //System.out.println("i="+i+" " +q.toString());
        }

        System.out.println(best);

    }

    public static int in() throws IOException {
        return Integer.parseInt(next());
    }

    public static long inl() throws IOException {
        return Long.parseLong(next());
    }

    public static String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(bf.readLine());
        return st.nextToken();
    }

}


import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class Round364_div2_C {

    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.flush();
    }

    public static void solve(FastReader in, PrintWriter out) {
        int n = in.readInt();
        String s = in.readString();

        int totalCnt = (int) s.chars().distinct().count();

        Map<Character, Integer> curCnts = new HashMap<>();

        int solution = s.length();
        int i = 0;
        for (int j = 0 ; j < s.length() ; j++) {
            // add s_j
            char sj = s.charAt(j);
            curCnts.put(sj, curCnts.getOrDefault(sj, 0) + 1);

            // contract s_i
            while (curCnts.getOrDefault(s.charAt(i), 0) > 1) {
                char si = s.charAt(i);
                int siCnt = curCnts.get(si);
                if (siCnt > 1) {
                    curCnts.put(si, siCnt - 1);
                } else {
                    curCnts.remove(si);
                }
                i++;
            }

            if (curCnts.size() == totalCnt) {
                solution = Math.min(solution, j - i + 1);
            }
        }

        out.println(solution);
    }

    /**
     * Custom buffered reader. Faster than Scanner and BufferedReader + StringTokenizer.
     */
    static class FastReader {
        private final InputStream stream;
        private int current;
        private int size;
        private byte[] buffer = new byte[1024 * 8];

        public FastReader(InputStream stream) {
            this.stream = stream;
            current = 0;
            size = 0;
        }

        public int readInt() {
            int sign = 1;
            int abs = 0;
            int c = readNonEmpty();
            if (c == '-') {
                sign = -1;
                c = readAny();
            }
            do {
                if (c < '0' || c > '9') {
                    throw new IllegalStateException();
                }
                abs = 10 * abs + (c - '0');
                c = readAny();
            } while (!isEmpty(c));
            return sign * abs;
        }

        public int[] readIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0 ; i < n ; i++) {
                array[i] = readInt();
            }
            return array;
        }

        public char readChar() {
            return (char) readNonEmpty();
        }

        public String readString() {
            StringBuffer sb = new StringBuffer();
            int c;
            do {
                c = readAny();
            } while (isEmpty(c));
            do {
                sb.append((char) c);
                c = readAny();
            } while (!isEmpty(c));
            return sb.toString();
        }

        private int readAny() {
            try {
                if (current >= size) {
                    current = 0;
                    size = stream.read(buffer);
                    if (size < 0) {
                        return -1;
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException("Failed to readAny next byte", e);
            }
            return buffer[current++];
        }

        private int readNonEmpty() {
            int result;
            do {
                result = readAny();
            } while (isEmpty(result));
            return result;
        }

        private static boolean isEmpty(int c) {
            return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == -1;
        }
    }
}


import java.util.*;
import java.io.*;

public class C{
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Solver solver = new Solver();
		solver.solve(in, out);
		out.close();
	}

	static class Solver{
		public void solve(InputReader in, PrintWriter out) {
			int n = in.nextInt();
			String s = in.next();
			HashMap<Character, Integer> map = new HashMap<>();
			for (int i = 0; i < n; ++ i) {
				map.put(s.charAt(i), 0);
			}
			int l = 0, r = 0, cnt = 0, ans = n;
			char c;
			while (l < n) {
				while (r < n && cnt < map.size()) {
					c = s.charAt(r);
					map.put(c, map.get(c) + 1);
					if (map.get(c) == 1) ++cnt;
					++r;
				}

				if (cnt == map.size() && r-l < ans)
					ans = r-l;

				c = s.charAt(l);
				map.put(c, map.get(c)-1);
				if (map.get(c) == 0) --cnt;
				++l;
			}
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader reader;
		StringTokenizer tokenizer;

		public InputReader (InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (tokenizer == null || ! tokenizer.hasMoreTokens()) {
				try{
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.*;

public class Q3a {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		in.nextLine();
		String s = in.nextLine();

		HashMap<Integer, Integer> seen = new HashMap<>();

		for (int i = 0; i < n; i++) {
			Character c = s.charAt(i);
			int ci = (int) c.charValue();
			// System.out.println(ci);
			seen.put(ci, seen.get(ci) == null ? 1 : seen.get(ci) + 1);
		}

		HashMap<Integer, Integer> sub = new HashMap<Integer, Integer>();
		int start = 0;
		int min = 10000000;
		for (int i = 0; i < n; i++) {
			Character c = s.charAt(i);
			int ci = (int) c.charValue();

			sub.put(ci, sub.get(ci) == null ? 1 : sub.get(ci) + 1);

			while(sub.size() == seen.size()) {
				min = Math.min(min, i - start + 1);
				c = s.charAt(start);
				start ++;
				ci = (int) c.charValue();
				if( sub.get(ci) == 1)
					sub.remove(ci);
				else
					sub.put(ci, sub.get(ci) - 1);
			}
		}

		System.out.print(min);

		// System.out.println( seen_all_at - begin + 1);

		in.close();
	}
}