import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

public class TestClass11 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputReader in=new InputReader(System.in);
		OutputWriter out=new OutputWriter(System.out);
		int n=in.readInt();
		String s=in.readString();
		int low[]=new int[26];
		int upper[]=new int[26];
		boolean islow[]=new boolean[26];
		boolean isupper[]=new boolean[26];
		Arrays.fill(low,Integer.MAX_VALUE);
		Arrays.fill(upper, Integer.MAX_VALUE);

		int ans[]=new int[n];
		int finalsans=Integer.MAX_VALUE;
		for(int i=0;i<n;i++){
			int c=s.charAt(i);
			if(c>='a'&&c<='z'){
				islow[c-'a']=true;
			}
			else{
				isupper[c-'A']=true;
			}

		}

		for(int i=n-1;i>=0;i--){
			int c=s.charAt(i);

			if(c>='a'&&c<='z'){
				low[c-'a']=i;
			}
			else{
				upper[c-'A']=i;
			}

			for(int j=0;j<26;j++){
				if(islow[j]==true){
					ans[i]=Math.max(ans[i], low[j]);
				}
			}
          for(int j=0;j<26;j++){
        	  if(isupper[j]==true){
        		  ans[i]=Math.max(ans[i], upper[j]);
				}
			}

          finalsans=Math.min(ans[i]-i+1, finalsans);
		}

		System.out.println(finalsans);

	}

}

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 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);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	public void flush() {
		writer.flush();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C {
	public static void main(String[] args) throws IOException {
		File inputFile = new File("entradaC");
		if (inputFile.exists())
			System.setIn(new FileInputStream(inputFile));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null) {
			int n = Integer.parseInt(line);
			char[] p = in.readLine().toCharArray();
			HashMap<Character, Integer> dif = new HashMap<>();
			for (int i = 0; i < p.length; i++)
				dif.put(p[i], 0);
			int ndif = dif.size();
			int head = 0, tail = 0, cnt = 0, ans = Integer.MAX_VALUE, cur;
			while (head < n) {
				cur = dif.get(p[head]);
				if (cur == 0)
					cnt++;
				dif.put(p[head], cur + 1);
				head++;
				if (cnt == ndif)
					ans = Math.min(ans, head - tail);
				while (tail < head && cnt == ndif) {
					cur = dif.get(p[tail]);
					if (cur == 1)
						cnt--;
					dif.put(p[tail], cur - 1);
					tail++;
					if (cnt == ndif)
						ans = Math.min(ans, head - tail);
				}
			}
			if (ndif == 1)
				ans = 1;
			out.append(ans + "\n");

		}
		System.out.print(out);
	}

	static int[] readInts(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		int a[] = new int[st.countTokens()], index = 0;
		while (st.hasMoreTokens())
			a[index++] = Integer.parseInt(st.nextToken());
		return a;
	}

	static long[] readLongs(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		long a[] = new long[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Long.parseLong(st.nextToken());
		return a;
	}

	static double[] readDoubles(String line) {
		StringTokenizer st = new StringTokenizer(line.trim());
		double a[] = new double[st.countTokens()];
		int index = 0;
		while (st.hasMoreTokens())
			a[index++] = Double.parseDouble(st.nextToken());
		return a;
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Round364C {
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = 0;

		String line = sc.nextLine();

		ArrayList<Character> poks = new ArrayList<Character>();
		boolean ex[] = new boolean[256];

		for(int i=0; i<n; i++)
		{
			if(!ex[line.charAt(i)])
			{
				ex[line.charAt(i)] = true;
				poks.add(line.charAt(i));
			}
		}

		int l = 0;
		int r = 0;
		int dist = 1;
		int occ[] = new int[256];
		occ[line.charAt(0)] = 1;

		int min = n;
		while(r < n)
		{
			if(dist == poks.size())
				min = Math.min(min, r - l + 1);
			if(l < r && dist == poks.size())
			{

				occ[line.charAt(l)]--;
				if(occ[line.charAt(l)] == 0)
					dist--;
				l++;
				continue;
			}
			if(r < n-1){
				occ[line.charAt(r+1)]++;
				if(occ[line.charAt(r+1)] == 1)
					dist++;
			}
			r++;
		}
		System.out.println(min);

	}

	static int n,k;
	static int dp[][][];

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}


import com.sun.org.apache.xml.internal.utils.StringComparable;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

public class Main {
    public static void main(String[] args) {
//     Test.testing();
        ConsoleIO io = new ConsoleIO();
        new Main(io).solve();
        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ArrayList<ArrayList<Integer>> gr;
    boolean[] visit;

    class Edge {
        public Edge(int u, int v, int c) {
            this.u = u;
            this.v = v;
            this.c = c;
        }

        public int u;
        public int v;
        public int c;
    }

    long MOD = 1_000_000_007;
    int N, M, K;
    double[][] map;

    public void solve() {
        String s = io.readLine();
        N = Integer.parseInt(s);
        char[] a = io.readLine().toCharArray();
        int[] look = new int[256];
        Arrays.fill(look, 10000);
        int k = 0;
        for (int i = 0; i < a.length; i++) {
            if (look[a[i]] == 10000) {
                look[a[i]] = k;
                k++;
            }
        }
        int res = N;
        long need = (1L << k) - 1;
        long mask = 0;
        int head = 0;
        int tail = 0;
        int[] c = new int[k];
        while (head < a.length) {
            while (head < a.length && mask != need) {
                int v = look[a[head]];
                if (c[v] == 0)
                    mask |= (1L << v);
                c[v]++;
                head++;
            }
            while (tail < head && mask == need) {
                res = Math.min(res, head - tail);

                int v = look[a[tail]];
                c[v]--;
                if (c[v] == 0)
                    mask ^= (1L << v);

                tail++;
            }
        }
        io.writeLine(res + "");
    }

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

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long readLong() {
        return Long.parseLong(this.readLine());
    }
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int readInt() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public void writeIntArray(int[] a) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length; i++) {if (i > 0) sb.append(' ');sb.append(a[i]);}
        this.writeLine(sb.toString());
    }
}
class Pair {
    public Pair(int a, int b) {this.a = a;this.b = b;}
    public int a;
    public int b;
}
class Tri {
    public Tri(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}


import java.util.*;

public class C{
	static String s;
	static long val[];
	static int N,size;
	static int index(char c){
		if(c <= 'Z'){
			return c - 'A';
		}else{
			return c - 'a' + ('Z' - 'A' + 1);
		}
	}

	static int l(int i){
		return (i<<1)+1;
	}
	static int r(int i){
		return (i<<1)+2;
	}

	static void setup(int l, int r, int i){
		if(l==r){
			val[i] = (1L<<index(s.charAt(l)));
		}else{
			int mid = (l+r)/2;
			setup(l,mid,l(i));
			setup(mid+1,r,r(i));
			val[i] = val[l(i)] | val[r(i)];
		}
	}

	static long query(int min, int max, int l, int r, int i){
		if(min <= l && r <= max){
			return val[i];
		}
		if(max < l || r < min)
			return 0;
		int mid = (l+r)/2;
		return query(min,max,l,mid,l(i)) | query(min,max,mid+1,r,r(i));
	}
	static long query(int min, int max){
		return query(min,max,0,N-1,0);
	}

	static int binarySearch(int start, long toFind){
		int max = N-1;
		int min = start;
		if(query(start,max) != toFind)
			return 1<<29;
		if(query(start,start) == toFind){
			return 1;
		}
		int ret = max - min + 1;
		while(min + 1 < max){
			int mid = (min+max)/2;
			if(query(start,mid) == toFind){
				max = mid;
			}else{
				min = mid;
			}
		}
		return max-start+1;
	}

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		s = sc.next();
		int size = 1;
		while(size <= N) size*=2;
		val = new long[size*2];
		setup(0,N-1,0);

		long toFind = query(0,N-1,0,N-1,0);
		long ans = 1L<<29;
		for(int i = 0; i < N; i++)
			ans = Math.min(ans,binarySearch(i,toFind));
		System.out.println(ans);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;

public class C {

	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	private static PrintStream out = System.out;

	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(in.readLine());
		char[] s = in.readLine().toCharArray();
		HashSet<Character> all = new HashSet<Character>();
		for (char c : s)
			all.add(c);
		int totalCount = all.size();
		HashMap<Character, Integer> cnts = new HashMap<Character, Integer>();
		int ans = Integer.MAX_VALUE;
		int x = 0;
		for (int y = 0; y < n; ++y) {
			if (!cnts.containsKey(s[y]))
				cnts.put(s[y], 0);
			cnts.put(s[y], cnts.get(s[y]) + 1);
			if (cnts.size() < totalCount)
				continue;
			while (cnts.get(s[x]) > 1) {
				cnts.put(s[x], cnts.get(s[x]) - 1);
				++x;
			}
			ans = Math.min(ans, y - x + 1);
		}
		out.println(ans);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * Created by Daniil on 5/29/2016.
 */
public class TaskB {

    public static int strIndex;
    public static void main(String[] args) throws IOException {

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        char[] s = scanner.next().toCharArray();

        int[][] r = new int[n][54];

        Set<Character> chars = new HashSet<>();

        for (int i= 0 ;i < n; ++ i)chars.add(s[i]);

        List<Character> all = new ArrayList<>();

        for (Character c: chars)all.add(c);

        for (int i = n - 1; i >= 0; -- i){
            for (int j = 0;j < 54; ++ j){
                if (i == n - 1){
                    r[i][j] = -1;
                }else {
                    r[i][j] = r[i + 1][j];
                }
            }
            r[i][getCode(s[i])] = i;
        }

        int res = n;

        for (int i =0; i < n; ++ i){
            int mx = 1;
            boolean fl = false;
            for (Character c: all){
                if (r[i][getCode(c)] == -1){
                    fl = true;
                    break;
                }
                mx = Math.max(mx, r[i][getCode(c)] - i + 1);
            }
            if (fl){
                System.out.println(res);
                return;
            }
            res = Math.min(res, mx);
        }
        System.out.println(res);

        scanner.close();
        //reader.close();
    }

    public static int getCode(char a){
        if (Character.isUpperCase(a))return a - 'A';
        return (a - 'a') + 26;
    }

    public static int getLetter(int n){
        if (n > 25)return (char)((n - 26) + 'a');
        return (char)((n) + 'A');
    }

    static class IO{

        BufferedReader reader;
        StringTokenizer tokenizer;
        PrintWriter writer;

        public void init() {
            try {
                reader = new BufferedReader(new InputStreamReader(System.in),8*1024);
                writer = new PrintWriter(System.out);
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(261);
            }
        }

        void destroy() {
            writer.close();
            System.exit(0);
        }

        void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        void println(Object... objects) {
            print(objects);
            writer.println();
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        String nextToken() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(nextLine());
            return tokenizer.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(nextToken());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(nextToken());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(nextToken());
        }
    }

}


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

@SuppressWarnings("unchecked")
public class P701A {

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

  void add(char c) {
    cc.put(c, cc.getOrDefault(c, 0) + 1);
  }

  void rem(char c) {
    Integer cnt = cc.get(c) - 1;
    if (cnt != 0) {
      cc.put(c, cnt);
    } else {
      cc.remove(c);
    }
  }

  public void run() throws Exception {
    int n = nextInt();

    char [] s = next().toCharArray();
    BitSet bs = new BitSet();
    for (char c : s) {
      bs.set(c);
    }

    int t = bs.cardinality();

    int m = Integer.MAX_VALUE;
    for (int i = 0, j = 0; i < n; i++) {
      while ((j < n) && (cc.size() < t)) {
        add(s[j]);
        j++;
      }

      if (cc.size() == t) {
        m = Math.min(m, j - i);
      }

      rem(s[i]);
    }

    println(m);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P701A().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    return ((b > 0) ? gcd(b, a % b) : a);
  }
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		String in1 = in.readLine();
		String store = "";
		HashSet<Character> contain = new HashSet<Character>();
		for(int i = 0; i < n;i++){
			if(!contain.contains(in1.charAt(i))){
				store += in1.charAt(i);
				contain.add(in1.charAt(i));
			}
		}
		int[] index = new int[store.length()];
		for(int i = 0; i < store.length(); i++){
			index [i] = -1;
		}
		HashSet<Integer> index2 = new HashSet<Integer>();
		ArrayList<Integer> index3 = new ArrayList<Integer>();
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int index4 = store.indexOf(in1.charAt(i));
			if(index[index4] == -1){
				index[index4] = i;
				index2.add(i);
				index3.add(i);
			}
			else{
				index2.remove(index[index4]);
				index2.add(i);
				index3.add(i);
				index[index4] = i;
			}
			if(index2.size() == index.length){
				while(!index2.contains(index3.get(0))){
					index3.remove(0);
				}
				min = Math.min(min, i - index3.get(0)+ 1);
			}

		}
		System.out.println(min);
	}

}


import java.io.* ;
import java.util.* ;
public class Codeshefcode {
	final static long r = 1000000007 ;
	static FasterScanner ip = new FasterScanner() ;
	static PrintWriter op = new PrintWriter(System.out) ;
	public static void main(String[] args) throws IOException{
	    int n = ip.i() ;
	    TreeMap<Character,Integer> map = new TreeMap<Character,Integer>() ;
	    TreeSet<Character> set = new TreeSet<Character>() ;
	    char c[] = ip.S().toCharArray() ;
	    for(char t : c)
	    	set.add(t) ;
	    int size = set.size() ;
	    for(int i=0 ; i<size ; i++)
	    	map.put(set.pollFirst(),i) ;
	    int a[] = new int[n] ;
	    for(int i=0 ; i<n ; i++)
	    	a[i]=map.get(c[i]) ;
	    int erl[][] = new int[size][n] ;
	    for(int i=0 ; i<size ; i++)
	    	for(int j=n-1 ; j>=0 ; j--)
	    		erl[i][j]=(a[j]==i) ? j : (j==n-1 ? -1 : erl[i][j+1]) ;
	    long min = Long.MAX_VALUE ;
	    for(int i=0 ; i<n ; i++){
	    	long maxt = Long.MIN_VALUE ;
	    	for(int j=0 ; j<size ; j++)
	    		if(erl[j][i]!=-1)
	    			maxt = Long.max(maxt,(erl[j][i]-i+1)) ;
	    		else{
	    			maxt = Long.MAX_VALUE ;
	    			break ;
	    		}
	    	min = Long.min(min,maxt) ;
	    }
	    op.print(min) ;
		Finish() ;
	}
	static void Finish(){
	   op.flush();
	   op.close();
    }
}
@SuppressWarnings("serial")
class MyList extends ArrayList<Long>{

}
class pair {
	private int x  ;
	private int y ;
	pair(int a,int b){
		x=a ;
		y=b ;
	}
	public int x(){
		return x ;
	}
	public int y(){
		return y ;
	}
}
class FasterScanner {
    private InputStream mIs;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    public FasterScanner() {
        this(System.in);
    }
    public FasterScanner(InputStream is) {
        mIs = is;
    }
    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = mIs.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public String nextLine(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }
    public String S(){
        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 long l(){
        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 int i(){
        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 boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    public boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Random;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
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);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            char[] str = IOUtils.readCharArray(in, n);
            for (int i = 0; i < n; i++) {
                if (str[i] <= 'Z') {
                    str[i] = (char) (str[i] - 'A');
                } else {
                    str[i] = (char) (str[i] - 'a' + 26);
                }
            }

            IntHashSet set = new IntHashSet();
            for (char c : str) {
                set.add(c);
            }
            int max = 26 + 26;
            int[][] next = new int[max][n];
            ArrayUtils.fill(next, -1);

            for (int i = n - 2; i >= 0; i--) {
                for (int ch = 0; ch < max; ch++) {
                    next[ch][i] = next[ch][i + 1];
                }
                next[str[i + 1]][i] = i + 1;
            }

            int ans = (int) 1e9;
            final int tagetCnt = set.size();
            for (int s = 0; s < n; s++) {
                boolean[] used = new boolean[max];
                used[str[s]] = true;
                int cnt = 1;
                int pos = s;
                while (cnt < tagetCnt) {
                    int nextPos = n;
                    for (int ch = 0; ch < max; ch++) {
                        if (!used[ch]) {
                            if (next[ch][pos] == -1) {
                                continue;
                            }
                            nextPos = Math.min(nextPos, next[ch][pos]);
                        }
                    }

                    pos = nextPos;
                    if (nextPos == n) {
                        break;
                    }
                    ++cnt;
                    used[str[nextPos]] = true;
                }
                if (pos == n) {
                    break;
                }
                ans = Math.min(ans, pos - s + 1);
            }
            out.printLine(ans);
        }

    }

    static interface IntCollection extends IntStream {
        public int size();

        default public void add(int value) {
            throw new UnsupportedOperationException();
        }

        default public IntCollection addAll(IntStream values) {
            for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {
                add(it.value());
            }
            return this;
        }

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

    }

    static class IntHashSet extends IntAbstractStream implements IntSet {
        private static final Random RND = new Random();
        private static final int[] SHIFTS = new int[4];
        private static final byte PRESENT_MASK = 1;
        private static final byte REMOVED_MASK = 2;
        private int size;
        private int realSize;
        private int[] values;
        private byte[] present;
        private int step;
        private int ratio;

        static {
            for (int i = 0; i < 4; i++) {
                SHIFTS[i] = RND.nextInt(31) + 1;
            }
        }

        public IntHashSet() {
            this(3);
        }

        public IntHashSet(int capacity) {
            capacity = Math.max(capacity, 3);
            values = new int[capacity];
            present = new byte[capacity];
            ratio = 2;
            initStep(capacity);
        }

        public IntHashSet(IntCollection c) {
            this(c.size());
            addAll(c);
        }

        public IntHashSet(int[] arr) {
            this(new IntArray(arr));
        }

        private void initStep(int capacity) {
            step = RND.nextInt(capacity - 2) + 1;
            while (IntegerUtils.gcd(step, capacity) != 1) {
                step++;
            }
        }

        public IntIterator intIterator() {
            return new IntIterator() {
                private int position = size == 0 ? values.length : -1;

                public int value() throws NoSuchElementException {
                    if (position == -1) {
                        advance();
                    }
                    if (position >= values.length) {
                        throw new NoSuchElementException();
                    }
                    if ((present[position] & PRESENT_MASK) == 0) {
                        throw new IllegalStateException();
                    }
                    return values[position];
                }

                public boolean advance() throws NoSuchElementException {
                    if (position >= values.length) {
                        throw new NoSuchElementException();
                    }
                    position++;
                    while (position < values.length && (present[position] & PRESENT_MASK) == 0) {
                        position++;
                    }
                    return isValid();
                }

                public boolean isValid() {
                    return position < values.length;
                }

                public void remove() {
                    if ((present[position] & PRESENT_MASK) == 0) {
                        throw new IllegalStateException();
                    }
                    present[position] = REMOVED_MASK;
                }
            };
        }

        public int size() {
            return size;
        }

        public void add(int value) {
            ensureCapacity((realSize + 1) * ratio + 2);
            int current = getHash(value);
            while (present[current] != 0) {
                if ((present[current] & PRESENT_MASK) != 0 && values[current] == value) {
                    return;
                }
                current += step;
                if (current >= values.length) {
                    current -= values.length;
                }
            }
            while ((present[current] & PRESENT_MASK) != 0) {
                current += step;
                if (current >= values.length) {
                    current -= values.length;
                }
            }
            if (present[current] == 0) {
                realSize++;
            }
            present[current] = PRESENT_MASK;
            values[current] = value;
            size++;
        }

        private int getHash(int value) {
            int hash = IntHash.hash(value);
            int result = hash;
            for (int i : SHIFTS) {
                result ^= hash >> i;
            }
            result %= values.length;
            if (result < 0) {
                result += values.length;
            }
            return result;
        }

        private void ensureCapacity(int capacity) {
            if (values.length < capacity) {
                capacity = Math.max(capacity * 2, values.length);
                rebuild(capacity);
            }
        }

        private void rebuild(int capacity) {
            initStep(capacity);
            int[] oldValues = values;
            byte[] oldPresent = present;
            values = new int[capacity];
            present = new byte[capacity];
            size = 0;
            realSize = 0;
            for (int i = 0; i < oldValues.length; i++) {
                if ((oldPresent[i] & PRESENT_MASK) == PRESENT_MASK) {
                    add(oldValues[i]);
                }
            }
        }

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void addAt(int index, int value);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

        default public void add(int value) {
            addAt(size(), value);
        }

    }

    static class IntegerUtils {
        public static int gcd(int a, int b) {
            a = Math.abs(a);
            b = Math.abs(b);
            while (b != 0) {
                int temp = a % b;
                a = b;
                b = temp;
            }
            return a;
        }

    }

    static abstract class IntAbstractStream implements IntStream {

        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

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

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

        }

    }

    static class IntHash {
        private IntHash() {
        }

        public static int hash(int c) {
            return c;
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static class IntArray extends IntAbstractStream implements IntList {
        private int[] data;

        public IntArray(int[] arr) {
            data = arr;
        }

        public int size() {
            return data.length;
        }

        public int get(int at) {
            return data[at];
        }

        public void addAt(int index, int value) {
            throw new UnsupportedOperationException();
        }

        public void removeAt(int index) {
            throw new UnsupportedOperationException();
        }

    }

    static interface IntSet extends IntCollection {
    }

    static class IOUtils {
        public static char[] readCharArray(InputReader in, int size) {
            char[] array = new char[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.readCharacter();
            }
            return array;
        }

    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static class ArrayUtils {
        public static void fill(int[][] array, int value) {
            for (int[] row : array) {
                Arrays.fill(row, value);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.FileReader;
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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public int[] parse(FastScanner in, int n) {
            String s = in.next();
            int[] temp = new int[n];
            for (int i = 0; i < n; ++i) {
                temp[i] = s.charAt(i) - 'A';
            }
            return temp;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] s = parse(in, n);

            Map<Integer, TreeSet<Integer>> map = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                if (map.containsKey(s[i])) {
                    map.get(s[i]).add(i);
                } else {
                    TreeSet<Integer> temp = new TreeSet<>();
                    temp.add(i);
                    map.put(s[i], temp);
                }
            }
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n; ++i) {
                int finalI = i;
                final Int integer = new Int();
                integer.x = i;
                map.forEach((Integer x, TreeSet set) -> {
                    if (x != s[finalI]) {
                        Integer temp = (Integer) set.higher(finalI);
                        if (temp == null) {
                            integer.x = -2;
                        } else {
                            if (integer.x != -2)
                                integer.x = Integer.max(integer.x, temp);
                        }
                    } else {
                    }
                });

                if (integer.x != -2) {
                    ans = Integer.min(ans, integer.x - i + 1);
                }
            }

            out.print(ans);
        }

        public class Int {
            int x;

            public Int() {
                x = -1;
            }

        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

    }
}


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

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;

	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

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

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

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

	final int oo = Integer.MAX_VALUE;

	int [][]s;
	int n, ALL;
	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		n = nextInt();
		char []a = next().toCharArray();
		s = new int[n][52];
		boolean []set = new boolean[52];

		for(int i = 0; i < n; ++i) {
			int pos = get(a[i]);
			if (!set[pos]) {
				++ALL;
				set[pos] = true;
			}
			for(int j = 0; j < 52; ++j) {
				if (i > 0) {
					s[i][j] += s[i-1][j];
				}
				if (j == pos) {
					s[i][j]++;
				}
			}
		}

		int ret = oo;
		for(int i = 0; i < n; ++i) {
			ret = Math.min(ret, get(i));
		}

		out.println(ret);
		out.close();
	}

	private int get(int i) {
		int lo = i - 1, hi = n;
		while(hi - lo > 1) {
			int m = lo + (hi - lo) / 2;
			int c = 0;
			for(int j = 0; j < 52; ++j) {
				if (sum(j, i, m) > 0) {
					++c;
				}
			}
			if (c < ALL) {
				lo = m;
			} else {
				hi = m;
			}
		}

		if (hi != n) {
			return hi - i + 1;
		}
		return oo;
	}

	private int sum(int pos, int l, int r) {
		int ret = s[r][pos];
		if (l > 0) ret -= s[l - 1][pos];
		return ret;
	}

	private int get(char x) {
		if ('a' <= x && x <= 'z') return (int)(x - 'a');
		return (int)(x - 'A' + 26);
	}

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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();
            String word = in.next();

            int cnt[] = new int[1000];

            int let = 0;
            Set<Character> set = new TreeSet<>();
            for (int i = 0; i < word.length(); i++) {
                set.add(word.charAt(i));
            }
            int uniq = set.size();
            int i = 0, j = -1;
            int ans = Integer.MAX_VALUE;
            while (i < N && j < N) {
                while (j + 1 < N && let < uniq) {
                    j++;
                    if (cnt[word.charAt(j)] == 0) {
                        let++;
                    }
                    cnt[word.charAt(j)]++;
                }
                if (let == uniq)
                    ans = Math.min(ans, j - i + 1);
                cnt[word.charAt(i)]--;
                if (cnt[word.charAt(i)] == 0) let--;
                i++;
            }
            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;
        }

        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.*;
import java.io.*;

public class C {
    public static void main(String[] args) throws IOException {
	BufferedReader in =
	    new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(in.readLine());
	char[] ps = in.readLine().toCharArray();
	HashMap<Character, TreeSet<Integer>> locs =
	    new HashMap<Character, TreeSet<Integer>>();
	HashSet<Character> poks = new HashSet<Character>();
	int lastNew = n;
	for (int i = 0; i < n; i++) {
	    if (!poks.contains(ps[i])) {
		poks.add(ps[i]);
		locs.put(ps[i], new TreeSet<Integer>());
		lastNew = i;
	    }
	    locs.get(ps[i]).add(i);
	}
	int max = lastNew;
	int minRange = max+1;
	for (int min = 0; min < n; min++) {
	    char pAtMin = ps[min];
	    Integer nextInd = locs.get(pAtMin).higher(min);
	    if (nextInd == null) break;
	    max = Math.max(max, nextInd);
	    minRange = Math.min(minRange, max-min);
	}
	System.out.println(minRange);
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Random;

public class ProblemC {

  public static void main(String[] args) throws IOException {
    init();
    new ProblemC().run();
    out.flush();
    out.close();
  }

  static void init() throws IOException {
    in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    out = new PrintWriter(new OutputStreamWriter(System.out));
    in.ordinaryChars(0, 65535);
    in.wordChars(0, 65535);
    in.whitespaceChars(' ', ' ');
    in.whitespaceChars('\n', '\n');
    in.whitespaceChars('\r', '\r');
  }

  // класс для пар
  class Pair<L, R> {
    private final L X;
    private final R Y;

    public Pair(L X, R Y) {
      this.X = X;
      this.Y = Y;
    }

    public L getX() {
      return X;
    }

    public R getY() {
      return Y;
    }

    @Override
    public int hashCode() {
      return X.hashCode() ^ Y.hashCode();
    }

    @Override
    public boolean equals(Object o) {
      if (!(o instanceof Pair)) return false;
      Pair pairo = (Pair) o;
      return X.equals(pairo.getX()) && Y.equals(pairo.getY());
    }
  }

  static final long INFL = 200000000000000000L;
  static final int INF = 2000000000;
  static final boolean DEBUG = true;

  static StreamTokenizer in;
  static PrintWriter out;

  static void print(String s) {
    print(s, 0);
  }

  static void print(String s, int debug) {
    if (debug == 0 || DEBUG) {
      out.print(s);
    }
  }

  static void println(String s) {
    println(s, 0);
  }

  static void println(String s, int debug) {
    if (debug == 0 || DEBUG) {
      out.println(s);
    }
  }

  static void printArray(int[] arr) {
    println(Arrays.toString(arr));
  }

  static void printArray(char[] arr) {
    println(Arrays.toString(arr));
  }

  static void printArray(String[] arr) {
    println(Arrays.toString(arr));
  }

  static void sort(int[] a) {
    Random rnd = new Random();
    for (int i = a.length - 1; i > 0; i--) {
      int index = rnd.nextInt(i);
      a[i] ^= a[index];
      a[index] ^= a[i];
      a[i] ^= a[index];
    }
    Arrays.sort(a);
  }

  static char[] inChars;
  static int inCharsInd;

  static String next() throws IOException {
    in.nextToken();
    return in.sval;
  }

  static char nextChar() throws IOException {
    while (inChars == null || inCharsInd >= inChars.length) {
      inChars = next().toCharArray();
      inCharsInd = 0;
    }
    return inChars[inCharsInd++];
  }

  static int nextInt() throws IOException {
    return Integer.valueOf(next());
  }

  static double nextDouble() throws IOException {
    return Double.valueOf(next());
  }

  static long nextLong() throws IOException {
    return Long.valueOf(next());
  }

  private void run() throws IOException {
    solve();
  }

  int K, L, M, N, P;

  private void solve() throws IOException {
    int[] countChars = new int['z' + 1];
    boolean[] gotIt = new boolean['z' + 1];
    int N = nextInt();
    int fullCount = 0;
    char[] chars = next().toCharArray();
    for (int i = 0; i < N; i++) {
      if (countChars[chars[i]] == 0) fullCount++;
      countChars[chars[i]]++;
    }
//    out.println(fullCount);

    countChars = new int['z' + 1];
    int answer = N;
    int start = 0, finish = 0;
    countChars[chars[start]]++;
    fullCount--;

    while (finish+1 < N){
      finish++;
      if (countChars[chars[finish]] == 0) {
        fullCount--;
      }
      countChars[chars[finish]]++;
      while (countChars[chars[start]] > 1){
        countChars[chars[start]]--;
        start++;
      }
      while (fullCount == 0){
//        out.println("start = " + (start+1));
//        out.println("finish = " + (finish+1));
        answer = Math.min(answer, finish-start+1);
        countChars[chars[start]]--;
        if (countChars[chars[start]] == 0) fullCount++;
        start++;
      }
    }

    out.println(answer);
  }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();

            int[] cnt = new int[26];
            int[] cnt2 = new int[26];
            int j = 0;
            int res = n;
            HashSet<Character> set = new HashSet<Character>();
            for (char c : s.toCharArray()) {
                set.add(c);
            }
            int m = set.size();

            for (int i = 0; i < n; ++i) {
                if (Character.isLowerCase(s.charAt(i))) {
                    cnt[s.charAt(i) - 'a']++;
                } else {
                    cnt2[s.charAt(i) - 'A']++;
                }
                while (isOK(cnt, cnt2, m)) {
                    res = Math.min(res, i - j + 1);
                    if (Character.isLowerCase(s.charAt(j))) {
                        cnt[s.charAt(j) - 'a']--;
                    } else {
                        cnt2[s.charAt(j) - 'A']--;
                    }
                    ++j;
                }
            }
            out.println(res);
        }

        boolean isOK(int[] cnt, int[] cnt2, int m) {
            int c = 0;
            for (int i = 0; i < 26; ++i) {
                if (cnt[i] > 0) {
                    ++c;
                }
            }
            for (int i = 0; i < 26; ++i) {
                if (cnt2[i] > 0) {
                    ++c;
                }
            }
            return c >= m;
        }

    }
}


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

public class Cf2207C {

    private static InputReader in = new InputReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);

    private static void solve() throws Exception {
        int n = in.readInt();
        String s = in.readString();
        int[] count = new int[200];
        boolean[] flag = new boolean[200];
        for(int i=0; i<n; ++i){
            flag[s.charAt(i)] = true;
        }
        int ref = 0;
        for(int i=0; i<200; ++i){
            if(flag[i]){
                ref++;
            }
        }

        int total = 0;
        int min  = Integer.MAX_VALUE;
        int j = 0;
        for(int i=0; i<n; ++i){
            if((j==n)&&(total<ref)){
                break;
            }
            if(total==ref){
                min = Math.min(min,j-i);
                count[s.charAt(i)]--;
                if(count[s.charAt(i)]==0){
                    total--;
                }
                continue;
            }
            for(;j<n; ++j){
                count[s.charAt(j)]++;
                if(count[s.charAt(j)]==1){
                    total++;
                }
                if(total==ref){
                    min = Math.min(min,j-i+1);
                    j++;
                    break;
                }
            }

            count[s.charAt(i)]--;
            if(count[s.charAt(i)]==0){
                total--;
            }

        }
        out.println(min);
    }

    public static void main(String[] args) throws Exception {
        solve();
        out.close();
    }

    private static class InputReader {
        private InputStream stream;
        private byte[] buffer;
        private int currentIndex;
        private int bytesRead;

        public InputReader(InputStream stream) {
            this.stream = stream;
            buffer = new byte[16384];
        }

        public InputReader(InputStream stream, int bufferSize) {
            this.stream = stream;
            buffer = new byte[bufferSize];
        }

        private int read() throws IOException {
            if (currentIndex >= bytesRead) {
                currentIndex = 0;
                bytesRead = stream.read(buffer);
                if (bytesRead <= 0) {
                    return -1;
                }
            }
            return buffer[currentIndex++];
        }

        public String readString() throws IOException {
            int c = read();
            while (!isPrintable(c)) {
                c = read();
            }
            StringBuilder result = new StringBuilder();
            do {
                result.appendCodePoint(c);
                c = read();
            } while (isPrintable(c));
            return result.toString();
        }

        public int readInt() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            int result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public long readLong() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            long result = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                result *= 10;
                result += (c - '0');
                c = read();
            } while (isPrintable(c));
            return sign * result;
        }

        public double readDouble() throws Exception {
            int c = read();
            int sign = 1;
            while (!isPrintable(c)) {
                c = read();
            }
            if (c == '-') {
                sign = -1;
                c = read();
            }
            boolean fraction = false;
            double multiplier = 1;
            double result = 0;
            do {
                if ((c == 'e') || (c == 'E')) {
                    return sign * result * Math.pow(10, readInt());
                }
                if ((c < '0') || (c > '9')) {
                    if ((c == '.') && (!fraction)) {
                        fraction = true;
                        c = read();
                        continue;
                    }
                    throw new InputMismatchException();
                }
                if (fraction) {
                    multiplier /= 10;
                    result += (c - '0') * multiplier;
                    c = read();
                } else {
                    result *= 10;
                    result += (c - '0');
                    c = read();
                }
            } while (isPrintable(c));
            return sign * result;
        }

        private boolean isPrintable(int c) {
            return ((c > 32) && (c < 127));
        }
    }

    private static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }

}


import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.HashSet;
public class C {
	public static void main(String args[]) {
		Kattio sc = new Kattio(System.in);
		int n = sc.getInt();
		String s = sc.getWord();
		int[] found = new int['z' + 1];
		int amount = 0;
		for(int i = 0; i<s.length(); i++) {
			char c = s.charAt(i);
			if(found[c] == 0) amount++;
			found[c]++;
		}
		int contains[] = new int['z' + 1];
		int min = n;
		int start = 0;
		int end = 0;
		int in = 0;
		while(true) {
			if(in<amount) {
				if(end == n) break;
				char c = s.charAt(end);
				if(contains[c] == 0) in++;
				contains[c]++;
				end++;
			} else {
				if(min>end-start) min = end-start;
				char c = s.charAt(start);
				if(contains[c] == 1) in--;
				contains[c]--;
				start++;
			}
		}
		System.out.println(min);

	}
}
class Kattio extends PrintWriter {
    public Kattio(InputStream i) {
	super(new BufferedOutputStream(System.out));
	r = new BufferedReader(new InputStreamReader(i));
    }
    public Kattio(InputStream i, OutputStream o) {
	super(new BufferedOutputStream(o));
	r = new BufferedReader(new InputStreamReader(i));
    }

    public boolean hasMoreTokens() {
	return peekToken() != null;
    }

    public int getInt() {
	return Integer.parseInt(nextToken());
    }

    public double getDouble() {
	return Double.parseDouble(nextToken());
    }

    public long getLong() {
	return Long.parseLong(nextToken());
    }

    public String getWord() {
	return nextToken();
    }

    private BufferedReader r;
    private String line;
    private StringTokenizer st;
    private String token;

    private String peekToken() {
	if (token == null)
	    try {
		while (st == null || !st.hasMoreTokens()) {
		    line = r.readLine();
		    if (line == null) return null;
		    st = new StringTokenizer(line);
		}
		token = st.nextToken();
	    } catch (IOException e) { }
	return token;
    }

    private String nextToken() {
	String ans = peekToken();
	token = null;
	return ans;
    }
}


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * @author grozhd
 */
public class P3 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = "";
        while (s.length() == 0) {
            s = sc.nextLine();
        }
        char[] pokemons = s.toCharArray();

        Set<Character> pokemonTypes = new HashSet<>();
        for (int i = 0; i < n; i++) {
            pokemonTypes.add(pokemons[i]);
        }

        int types = pokemonTypes.size();

        int l = 0;
        int r = 0;
        int min = n;
        Map<Character, Integer> currentPokemons = new HashMap<>();

        while (r < n) {
            while (currentPokemons.size() < types && r < n) {
                char pokemon = pokemons[r++];
                currentPokemons.merge(pokemon, 1, (a, b) -> a + b);
            }
            min = Math.min(r - l, min);

            while (currentPokemons.size() == types) {
                char pokemon = pokemons[l++];
                if (currentPokemons.get(pokemon) == 1) {
                    currentPokemons.remove(pokemon);
                } else {
                    min = Math.min(r - l, min);
                    currentPokemons.put(pokemon, currentPokemons.get(pokemon) - 1);
                }
            }
        }

        min = Math.min(min, r - l + 1);
        min = Math.max(min, types);

        System.out.println(min);

    }
}


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

public class Main {

    void change(int [] all, char c, int val) {
        if (Character.isUpperCase(c))
            all[c - 'A' + 26] += val;
        else
            all[c - 'a'] += val;
    }

    int countDistinct(int [] a) {
        int res = 0;
        for (int i = 0 ; i< a.length ; i++) {
            if (a[i] > 0)
                res ++;
        }
        return res;
    }
    public void solve() throws IOException {
        int n = nextInt();
        String s = next();

        int [] all = new int[52];
        for (int i = 0 ; i < s.length() ; i++) {
            char c = s.charAt(i);
            change(all, c, 1);
        }
        int distinct = countDistinct(all);

        int [] window = new int[52];
        int best = n;
        for (int i = 0, j = 0 ; i < s.length() ; i++) {

            if (i > 0) {
                change(window, s.charAt(i-1), -1);
            }
            while (j < s.length()) {
                if (countDistinct(window) == distinct)
                    break;

                change(window, s.charAt(j), 1);
                j ++;
            }
            if (countDistinct(window) < distinct)
                break;

            best = Math.min(best, j - i);
        }
        out.println(best);
    }

    BufferedReader bf;
    StringTokenizer st;
    PrintWriter out;

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(bf.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    public Main() throws IOException {
        bf = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new OutputStreamWriter(System.out));
        solve();
        bf.close();
        out.close();
    }

    public static void main(String args[]) throws IOException {
        new Main();
    }
}


import java.util.*;

public class Main {
	private static Scanner in = new Scanner(System.in);
	public static void main(String args[]){
		int n = in.nextInt();
		String s = in.next();
		if(n==1)
			System.out.println("1");
		else{
			int j=0,i=1,ans=s.length();
			int h[]=new int[128];
			h[(int)s.charAt(0)]=1;
			while(i<n){
				if(h[(int)s.charAt(i)]==0)
					ans = i-j+1;
				h[(int) s.charAt(i)]++;
				while(j<i && h[(int)s.charAt(j)]>1){
					h[(int)s.charAt(j)]--;
					j++;
					ans = Math.min(ans, i-j+1);
				}
				i++;
			}
			System.out.println(ans);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class CTask {

    public static void main(String[] args) throws IOException {
        MyInputReader in = new MyInputReader(System.in);
        HashMap<Character, Integer> m = new HashMap<Character, Integer>();
        int n = in.nextInt();
        char[] s = in.next().toCharArray();

        for (int i = 0; i < n; i++) {
            m.put(s[i], 0);
        }
        int mx = m.size();
        int start = 0;
        int end = 0;
        int min = Integer.MAX_VALUE;
        int cur = 0;
        while (end < n) {
            while (end < n && cur != mx) {
                int x = m.get(s[end]);
                if (x == 0) {
                    cur += 1;
                }
                m.put(s[end], x + 1);
                end += 1;
            }
            while (start <= end && cur == mx) {
                int x = m.get(s[start]);
                m.put(s[start], x - 1);
                if (x - 1 == 0) {
                    cur -= 1;
                }
                start += 1;
            }
            min = Math.min(min, end - start + 1);
        }
        System.out.println(min);
    }

    static class Pair {

        long x;
        long y;

        public Pair(long x, long y) {
            this.x = x;
            this.y = y;
        }

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

            Pair pair = (Pair) o;

            if (x != pair.x) return false;
            return y == pair.y;

        }

        @Override
        public int hashCode() {
            int result = (int) (x ^ (x >>> 32));
            result = 31 * result + (int) (y ^ (y >>> 32));
            return result;
        }
    }

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

        public MyInputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }

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

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rene
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            HashMap<Character, Integer> indexMap = new HashMap<>();
            for (int i = 0; i < n; i++) {
                char c = s.charAt(i);
                if (!indexMap.containsKey(c)) {
                    indexMap.put(c, indexMap.size());
                }
            }
            int[] last = new int[indexMap.size()];
            Arrays.fill(last, -1_000_000);
            int answer = n;
            for (int i = 0; i < n; i++) {
                int index = indexMap.get(s.charAt(i));
                last[index] = i;
                int first = i;
                for (int a : last) first = Math.min(first, a);
                int visits = i - first + 1;
                answer = Math.min(answer, visits);
            }
            out.println(answer);
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Scanner;
import java.util.TreeSet;

public class Main3 {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = sc.nextInt();
        String S = sc.next();
        HashSet<Character> unique = new HashSet<>();
        for(char c : S.toCharArray()){
            unique.add(c);
        }
        int number = unique.size();

        Hashtable<Character, Integer> indexes = new Hashtable<>();
        TreeSet<Integer> tree = new TreeSet<>();

        int min = N+1;
        int total = 0;
        for(int i = 0; i<N; i++){
            char c = S.charAt(i);
            if(!indexes.containsKey(c)){
                total++;
                indexes.put(c, i);
                tree.add(i);
            }
            else{
                int old = indexes.get(c);
                indexes.put(c, i);
                tree.remove(old);
                tree.add(i);
            }

            if(total == number){
                int dist = tree.last() - tree.first() + 1;
                min = Math.min(dist, min);
            }
        }

        System.out.println(min);
    }
}


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

public class CF1009E {
	static final int MD = 998244353;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] aa = new int[1 + n];
		for (int i = 1, a = 0; i <= n; i++)
			aa[i] = a = (a + Integer.parseInt(st.nextToken())) % MD;
		int[] pp = new int[n];
		pp[0] = 1;
		for (int i = 1, p = 1; i < n; i++) {
			pp[i] = p;
			p = p * 2 % MD;
		}
		int d = 0;
		long ans = 0;
		for (int i = n - 1; i >= 0; i--) {	// rest at i
			d = (d * 2 % MD + aa[n - 1 - i]) % MD;	// rest again before n
			ans = (ans + (long) (d + aa[n - i]) * pp[i]) % MD;
		}
		System.out.println(ans);
	}
}


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

public class Main
	{
		class node{
		int data;
		node next;
		public node(int val){
			data=val;
			next=null;
		}
	}
	class linkedlist{
		node start;
		node end;
		int size;
		int turn;
		public linkedlist(){
			start=null;
			end=null;
			size=0;
		}
		void add(int val){
			if(size==0){
				node t=new node(val);
				start=t;
				end=t;
				size++;
			}
			else{
				node t=new node(val);
				end.next=t;
				end=end.next;
				size++;
			}
		}
		void myfunc(){
			if(start.data>start.next.data){
				// System.out.println("me ni hu");
				node t=new node(start.next.data);
				start.next=start.next.next;
				end.next=t;
				end=end.next;
			}
			else{
				// System.out.println("me hu");
				int t=start.data;
				start=start.next;
				add(t);
				size--;
			}
		}
		int findmax(){
			int m=0;
			node temp=start;
			for(int i=0;i<size;i++){
				if(temp.data>m){
					m=temp.data;
				}
				temp=temp.next;
			}
			return m;
		}
		void display(){
			node temp=start;
			for(int i=0;i<size;i++){
				System.out.print(temp.data+" ");
				temp=temp.next;
			}
			System.out.println("");
		}
	}
	linkedlist l;
	public Main(){
		l=new linkedlist();
	}
	public static void main(String [] argv) throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		Main ma=new Main();
		String[] l1=in.readLine().split(" ");
		int n=Integer.parseInt(l1[0]);
		int q=Integer.parseInt(l1[1]);
		String[] ar=in.readLine().split(" ");
		int a1=Integer.parseInt(ar[0]);
		int b1=Integer.parseInt(ar[1]);
		for(int i=0;i<n;i++){
			ma.l.add(Integer.parseInt(ar[i]));
		}
		int m=ma.l.findmax();
		int[][] pair=new int[n][2];
		int t=0;
		for(int i=0;i<n;i++){
			if(ma.l.start.data==m)
				break;
			ma.l.myfunc();
			pair[t][0]=ma.l.start.data;
			pair[t][1]=ma.l.start.next.data;
			t++;
		}
		int rl[]=new int[n];
		node temp=ma.l.start;
		for(int i=0;i<n;i++){
			rl[i]=temp.data;
			temp=temp.next;
		}
		for(int i=0;i<q;i++){
			long a=Long.parseLong(in.readLine());
			if(a==1){
				System.out.println(a1 + " " + b1);
			}
			else{
				if(a<=t+1){
					System.out.println(pair[(int)(a-2)][0]+" "+pair[(int)(a-2)][1]);
				}
				else{
					if((a-t)%(n-1)==0){
						System.out.println(rl[0]+" "+rl[n-1]);
					}
					else{
						System.out.println(rl[0]+" "+rl[(int)((a-t)%(n-1))]);
					}
				}
			}
		}
	}
}


import java.io.*;
import java.util.*;
public class D999 {
    public static void main(String args[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int req=n/m;
        int arr[]=new int[n+1];
        int size[]=new int[m];
        List<Integer> list[]=new ArrayList[m];
        for(int i=0;i<m;i++)
        {
            list[i]=new ArrayList<>();
        }
        for(int i=1;i<=n;i++)
        {
            arr[i]=sc.nextInt();
            size[arr[i]%m]++;
            list[arr[i]%m].add(i);
        }
        long tot=0;int x=0,y=0;
        List<Integer> idx=new ArrayList<>();
        for(int i=0;i < 2*m;i++)
        {
            //System.out.println(i+" "+size[i%m]);
            if(size[i%m]>req)
            {
                for(int j=0;j<size[i%m]-req;j++)
                {
                    idx.add(list[i%m].get(j));
                    y++;

                }
                size[i%m]=req;
                //System.out.println(i+" "+x+" "+y);
            }
            else if(size[i%m]<req)
            {
                //System.out.println(idx+" "+i);
                while(x!=y && size[i%m]<req)
                {
                    int num=arr[idx.get(x)];
                    int gg=i-num%m;
                    tot+=gg;
                    arr[idx.get(x)]+=gg;
                    x++;
                    size[i%m]++;
                }
            }
        }
        System.out.println(tot);
        for(int i=1;i<=n;i++)
        {
            System.out.print(arr[i]+" ");
        }
    }
}


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

/**
 * @author Don Li
 */
public class EhabAndAComponentChoosingProblem {

    long INF = (long) 1e18;

    int n;
    int[] a;

    int[][] G;

    void solve() {
        n = in.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int[] fr = new int[n - 1], to = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            fr[i] = in.nextInt() - 1;
            to[i] = in.nextInt() - 1;
        }
        G = build_graph(n, fr, to);

        int[][] ret = bfs(G, 0);
        int[] par = ret[0], ord = ret[2];

        long best = -INF;
        long[] dp = new long[n];
        for (int i = n - 1; i >= 0; i--) {
            int u = ord[i];
            dp[u] = a[u];
            for (int v : G[u]) {
                if (v != par[u]) {
                    if (dp[v] > 0) dp[u] += dp[v];
                }
            }
            best = Math.max(best, dp[u]);
        }

        int k = 0;
        for (int i = n - 1; i >= 0; i--) {
            int u = ord[i];
            dp[u] = a[u];
            for (int v : G[u]) {
                if (v != par[u]) {
                    if (dp[v] > 0) dp[u] += dp[v];
                }
            }
            if (dp[u] == best) {
                dp[u] = -INF;
                k++;
            }
        }

        out.printf("%d %d%n", best * k, k);
    }

    int[][] bfs(int[][] G, int root) {
        int n = G.length;

        int[] par = new int[n];
        Arrays.fill(par, -1);

        int[] dep = new int[n];
        dep[root] = 0;

        int[] qu = new int[n];
        qu[0] = root;
        for (int l = 0, r = 1; l < r; l++) {
            int u = qu[l];
            for (int v : G[u]) {
                if (v != par[u]) {
                    qu[r++] = v;
                    par[v] = u;
                    dep[v] = dep[u] + 1;
                }
            }
        }

        return new int[][]{par, dep, qu};
    }

    int[][] build_graph(int n, int[] from, int[] to) {
        int[][] G = new int[n][];
        int[] cnt = new int[n];
        for (int i = 0; i < from.length; i++) {
            cnt[from[i]]++;
            cnt[to[i]]++;
        }
        for (int i = 0; i < n; i++) G[i] = new int[cnt[i]];
        for (int i = 0; i < from.length; i++) {
            G[from[i]][--cnt[from[i]]] = to[i];
            G[to[i]][--cnt[to[i]]] = from[i];
        }
        return G;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new EhabAndAComponentChoosingProblem().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

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

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

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

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

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

1088_E. Ehab and a component choosing problem


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

public class Main implements Runnable {

	public void _main() throws IOException {
		int n = nextInt();
		int k = nextInt();
		boolean[] p = new boolean[n + 1];
		Arrays.fill(p, true);
		List<Integer> primes = new ArrayList<Integer>();
		for (int i = 2; i <= n; i++)
			if (p[i]) {
				primes.add(i);
				for (int j = i + i; j <= n; j += i)
					p[j] = false;
			}
		boolean[] ok = new boolean[n + 1];
		for (int i = 0; i < primes.size() - 1; i++) {
			int x = primes.get(i);
			int y = primes.get(i + 1);
			if (x + y + 1 <= n)
				ok[x + y + 1] = true;
		}
		for (int i = 2; i <= n; i++)
			if (p[i] && ok[i]) {
				--k;
			}
		out.println(k <= 0 ? "YES" : "NO");
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	private String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String rl = in.readLine();
			if (rl == null)
				return null;
			st = new StringTokenizer(rl);
		}
		return st.nextToken();
	}

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

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

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			_main();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(202);
		}
	}

}


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

import static java.lang.Math.*;

public class Main {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	void solve() throws IOException {
		int n=ni();
		int k=ni();
		boolean[] t = new boolean[n+1];
		for(int i=2;i<=n;i++){
		t[i]=false;
		}
		int p=2;

		while(true){
			int pointer=2;
		while(pointer*p<=n){
			t[pointer*p]=true;
			pointer++;
		}

		boolean flag=false;
		for(int i=p+1;i<=n;i++){
			if(!t[i]){p=i;flag=true;break;}
		}
		if(!flag)break;
		}
		List<Integer> lst=new ArrayList<Integer>();

		int countN=0;
		for(int i=1;i<=n;i++){
			if(!t[i]){lst.add(i);countN++; }
		}
		int count=0;

		String resulPO="NO";
		for(int i=2;i<countN;i++){

			boolean result=false;
			for(int j=0;j<i;j++){
				if(lst.get(j)+lst.get(j+1)+1==lst.get(i)){
					result=true;
					//out.println(lst.get(j)+"+"+lst.get(j+1)+"+"+1+"=="+lst.get(i));
					break;
				}
			}
			if(result)count++;
		}
		if(count>=k)resulPO="YES";
		else resulPO="NO";
		out.print(resulPO);

	}

	public Main() throws IOException {
		Locale.setDefault(Locale.US);
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		in.close();
		out.close();
	}

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

	int ni() throws IOException {
		return Integer.valueOf(ns());
	}

	long nl() throws IOException {
		return Long.valueOf(ns());
	}

	double nd() throws IOException {
		return Double.valueOf(ns());
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}
}


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

public class a {

	boolean[] isp;
	ArrayList<Integer> primes;

	private void solve() throws Exception {
		int n = nextInt();
		int k = nextInt();
		int cnt = 0;
		primes = new ArrayList<Integer>();
		isp = new boolean[n + 1];
		Arrays.fill(isp, true);
		for (int i = 2; i <= n; ++i) {
			for (int j = 2; j * j <= i; ++j)
				if (i % j == 0)
					isp[i] = false;
			if (isp[i])
				primes.add(i);
		}
		for (int i = 2; i <= n; ++i)
			if (isp[i]) {
				boolean can = false;
				for (int j = 0; j < primes.size() - 1; ++j) {
					int sum = primes.get(j) + primes.get(j + 1) + 1;
					if (i == sum)
						can = true;
				}
				if (can)
					++cnt;
			}
		if (cnt >= k)
			out.print("YES");
		else
			out.print("NO");
	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			NOO(e);
		} finally {
			out.close();
		}
	}

	PrintWriter out;
	BufferedReader in;
	StringTokenizer St;

	void NOO(Exception e) {
		e.printStackTrace();
		System.exit(1);
	}

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

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

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

	String nextToken() {
		while (!St.hasMoreTokens()) {
			try {
				String line = in.readLine();
				St = new StringTokenizer(line);
			} catch (Exception e) {
				NOO(e);
			}
		}
		return St.nextToken();
	}

	private a(String name) {
		try {
			in = new BufferedReader(new FileReader(name + ".in"));
			St = new StringTokenizer("");
			out = new PrintWriter(new FileWriter(name + ".out"));
		} catch (Exception e) {
			NOO(e);
		}
	}

	private a() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			St = new StringTokenizer("");
			out = new PrintWriter(System.out);
		} catch (Exception e) {
			NOO(e);
		}
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new a().run();
	}

}


//package round17;

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

public class A {

	static StreamTokenizer in =
		new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

	static int nextInt() throws IOException{
		in.nextToken();
		return (int)in.nval;
	}

	static PrintWriter out = new PrintWriter(System.out);

	static boolean prime(int n){
		int j = 2;
		while (j*j <= n)
			if (n%j == 0) return false;
			else j++;

		return true;
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			k = nextInt(),
			a[] = new int[n];

		int s = 0;
		for (int i=2; i<=n; i++)
			if (prime(i))
				a[s++] = i;

		int m = 0;
		for (int i=2; i<s; i++)
			for (int j=i-1; j>0; j--)
				if (a[i] == a[j]+a[j-1]+1){
					m++;
					break;
				}

		if (m >= k) out.println("YES");
		else out.println("NO");
		out.flush();
	}

}


import java.util.BitSet;
import java.util.Scanner;

public class A {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		BitSet primes = primes(1001);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int count = 0;
		for (int i = 2; i <= N; ++i) {
			if (!primes.get(i)) continue;
			int res = i - 1;
			boolean found = false;
			for (int j = 2; j <= i / 2; ++j) {
				if (primes.get(j) && primes.nextSetBit(j + 1) == res - j) {
					found = true;
					break;
				}
			}
			if (found) {
				++count;
			}
		}
		System.out.println(count >= K ? "YES" : "NO");
	}

	public static BitSet primes(int max) {
		BitSet primeSet = new BitSet(max + 1);
		if (max < 2) {
			return primeSet;
		}
		int limit = (int) Math.sqrt(max + 1);
		primeSet.set(2);
		for (int i = 3; i < max + 1; i += 2) {
			primeSet.set(i);
		}
		for (int i = 3; i <= limit; i += 2) {
			if (!primeSet.get(i)) {
				continue;
			}
			for (int j = i * i; j < max; j += i) {
				primeSet.clear(j);
			}
		}
		return primeSet;
	}

}


import java.awt.*;
import java.math.*;
import java.util.regex.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Integer.parseInt;
import static java.util.AbstractMap.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import java.awt.geom.*;
import java.util.*;
import java.text.*;
import java.io.*;

public class A {

	public static void main(String[] args) throws Exception {
		boolean submit = true;
		Scanner sc = submit ? new Scanner(System.in) : new Scanner(new File("A.in"));
		while(sc.hasNext()) {
			int n = sc.nextInt(), k = sc.nextInt();
			boolean p[] = sieveOfEratosthenes(1001);
			ArrayList<Integer> nolds = new ArrayList<Integer>();

			for(int i = 0, prev = 0; i < p.length; i++) {
				if(p[i]) {
					nolds.add(prev+i + 1);
					prev = i;
				}
			}

			//System.out.println(nolds);

			int c = 0;
			for(int i : nolds)
				if(i >= 2 && i <= n && p[i])
					c++;

			System.out.println(c >= k ? "YES" : "NO");

		}

	}

	//prime[i] = true iff i is prime, prime[0] = prime[1] = false and i can be from 0 to n (both inclusive)
    static boolean[] sieveOfEratosthenes(int n) {
        boolean prime[] = new boolean[n+1];
        fill(prime, 2, n, true);
        for(int i = 2; i <= n; i++)
            if(prime[i])
                for(int j = i*i; j <= n; j+=i) //check for i*i overflow
                    prime[j] = false;
        return prime;
    }

}


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

public class Main {

    StreamTokenizer in;
    PrintWriter out;
    public static void main(String[] args) throws IOException
    {
        new Main().run();
    }
    public void run() throws IOException
    {
    //	in =new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
    //  out = new PrintWriter(new FileWriter("output.txt"));

        in =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	   out = new PrintWriter(new OutputStreamWriter(System.out));
             solve();
        out.flush();

    }
    public int nextInt() throws IOException
    {
        in.nextToken();
        return (int) in.nval;
    }
    boolean pr(int i)
    {
    	if(i<4) return true;
    	for(int j=2;j<Math.sqrt(i)+1;j++)
    		if(i%j==0)
    			return false;
    	return true;
    }
    public void solve() throws IOException
    {
    	int n=nextInt(),k=nextInt();
    	int prost[]=new int[1000];
    	boolean now[]=new boolean[10000];
    	int a=0;
    	for(int i=2;i!=1000;i++)
    		if(pr(i))
    			prost[a++]=i;
    	for(int i=0;i!=a-1;i++)
    	{
    		if(pr(prost[i]+prost[i+1]+1))
    			now[prost[i]+prost[i+1]+1]=true;
    	}
    	int answ=0;
    	for(int i=0;i!=n+1;i++)
    		if(now[i])
    			answ++;
    	if(answ>=k)
    		out.print("YES");
    	else
    		out.print("NO");
    }

}


import java.util.*;

public class A
{
	public static void main(String args[])
	{
		boolean[] b = new boolean[11000];
		Arrays.fill(b, true);
		b[0] = b[1] = false;

		for(int i=2;i < b.length;i++)
		{
			if(!b[i])
				continue;

			for(int j=2;i*j<b.length;j++)
				b[i*j] = false;
		}

		int[] p = new int[11000];
		int pn = 0;

		for(int i=0;i < b.length;i++)
		{
			if(b[i])
				p[pn++] = i;
		}

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int k = scan.nextInt();

		int rtn = 0;

		for(int j=0;p[j] <= n;j++)
		{
			//Try to make sum
			for(int h=0;h <= j;h++)
			{
				if(p[h] + p[h+1] + 1 == p[j])
				{
					rtn++;
					break;
				}
			}
		}

		System.out.println(rtn >= k ? "YES" : "NO");

	}
}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int K = s.nextInt();

        int[] primes = getPrimesFast(N);
        Set<Integer> ints = new HashSet<Integer>();
        for(int i=0;i<primes.length;i++) {
            ints.add(primes[i]);
        }

        for(int i=1;i<primes.length;i++) {
            ints.remove(primes[i] + primes[i-1]+1);
        }

        boolean res = primes.length - ints.size() >= K;
        System.out.print(res?"YES":"NO");

    }

    public static int[] getPrimesFast(int n) {
    if (n <= 1) {
      return new int[0];
    }
    boolean[] b = new boolean[n + 1];
    int m = n - 1;
    for (int i = 2; i * i <= n; i++) {
      if (!b[i]) {
        for (int j = i + i; j <= n; j += i) {
          if (!b[j]) {
            m--;
            b[j] = true;
          }
        }
      }
    }
    int[] primes = new int[m];
    int j = 0;
    for (int i = 2; i <= n; i++) {
      if (!b[i]) {
        primes[j++] = i;
      }
    }
    return primes;
  }
}