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

public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		Set<Long> set = new LinkedHashSet<Long>();
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextLong();
		}
		int ans = n - 1;
		for (int j = 0; j < n; j++) {
			boolean flag = true;
			int k = 0;
			for (int i = 0; i < j; i++) {
				set.add(arr[i]);
				if (set.size() == k) {
					flag = false;
					break;
				}
				k = set.size();
			}
			int su = n;
			for (int i = n - 1; i >= j; i--) {
				if (set.contains(arr[i])) {
					break;
				}
				else {
					set.add(arr[i]);
					su = i;
				}
			}
			if (flag) {
				ans = Math.min(ans, su - j);
			}
			set.clear();
		}
		System.out.println(ans);
	}
}


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

public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		Set<Integer> set = new HashSet<Integer>();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		int k = 0;
		for (int i = 0; i < n; i++) {
			set.add(arr[i]);
			if (set.size() == k) {
				break;
			}
			k = set.size();
		}
		for (int i = n - 1; i >= 0; i--) {
			if (set.contains(arr[i])) {
				break;
			}
			set.add(arr[i]);
			k += 1;
		}
		System.out.println(n - k);
	}
}


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

public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		Set<Long> set = new TreeSet<Long>();
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextLong();
		}
		int ans = n - 1;
		for (int j = 0; j < n; j++) {
			boolean flag = true;
			int k = 0;
			for (int i = 0; i < j; i++) {
				set.add(arr[i]);
				if (set.size() == k) {
					flag = false;
					break;
				}
				k = set.size();
			}
			int su = n;
			for (int i = n - 1; i >= j; i--) {
				if (set.contains(arr[i])) {
					break;
				}
				else {
					set.add(arr[i]);
					su = i;
				}
			}
			if (flag) {
				ans = Math.min(ans, su - j);
			}
			set.clear();
		}
		System.out.println(ans);
	}
}


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

public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		Set<Long> set = new HashSet<Long>();
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextLong();
		}
		int ans = n - 1;
		for (int j = 0; j < n; j++) {
			boolean flag = true;
			int k = 0;
			for (int i = 0; i < j; i++) {
				set.add(arr[i]);
				if (set.size() == k) {
					flag = false;
					break;
				}
				k = set.size();
			}
			int su = n;
			for (int i = n - 1; i >= j; i--) {
				if (set.contains(arr[i])) {
					break;
				}
				else {
					set.add(arr[i]);
					su = i;
				}
			}
			if (flag) {
				ans = Math.min(ans, su - j);
			}
			set.clear();
		}
		System.out.println(ans);
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.BufferedOutputStream;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.Flushable;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Closeable;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			Input in = new Input(inputStream);
			Output out = new Output(outputStream);
			BUniqueness solver = new BUniqueness();
			solver.solve(1, in, out);
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<29);
		thread.start();
		thread.join();
	}
	static class BUniqueness {
		private final int INF = 1_000_000_000;

		public BUniqueness() {
		}

		public void solve(int kase, Input in, Output pw) {
			int n = in.nextInt();
			int[] arr = new int[n];
			for(int i = 0; i<n; i++) {
				arr[i] = in.nextInt();
			}
			int ans = INF;
			HashSet<Integer> soFar = new HashSet<>();
			for(int i = 0; i<n; i++) {
				HashSet<Integer> cur = new HashSet<>(soFar);
				int j;
				for(j = n-1; j>=0&&j>=i; j--) {
					if(cur.contains(arr[j])) {
						break;
					}
					cur.add(arr[j]);
				}
				ans = Math.min(ans, j-i+1);
				Utilities.Debug.dbg(i, j);
				if(soFar.contains(arr[i])) {
					break;
				}
				soFar.add(arr[i]);
			}
			pw.println(ans);
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			this(is, 1<<20);
		}

		public Input(InputStream is, int bs) {
			br = new BufferedReader(new InputStreamReader(is), bs);
			st = null;
		}

		public boolean hasNext() {
			try {
				while(st==null||!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken();
		}

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

	}

	static class Utilities {
		public static class Debug {
			public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;

			private static <T> String ts(T t) {
				if(t==null) {
					return "null";
				}
				try {
					return ts((Iterable) t);
				}catch(ClassCastException e) {
					if(t instanceof int[]) {
						String s = Arrays.toString((int[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof long[]) {
						String s = Arrays.toString((long[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof char[]) {
						String s = Arrays.toString((char[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof double[]) {
						String s = Arrays.toString((double[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof boolean[]) {
						String s = Arrays.toString((boolean[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}
					try {
						return ts((Object[]) t);
					}catch(ClassCastException e1) {
						return t.toString();
					}
				}
			}

			private static <T> String ts(T[] arr) {
				StringBuilder ret = new StringBuilder();
				ret.append("{");
				boolean first = true;
				for(T t: arr) {
					if(!first) {
						ret.append(", ");
					}
					first = false;
					ret.append(ts(t));
				}
				ret.append("}");
				return ret.toString();
			}

			private static <T> String ts(Iterable<T> iter) {
				StringBuilder ret = new StringBuilder();
				ret.append("{");
				boolean first = true;
				for(T t: iter) {
					if(!first) {
						ret.append(", ");
					}
					first = false;
					ret.append(ts(t));
				}
				ret.append("}");
				return ret.toString();
			}

			public static void dbg(Object... o) {
				if(LOCAL) {
					System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [");
					for(int i = 0; i<o.length; i++) {
						if(i!=0) {
							System.err.print(", ");
						}
						System.err.print(ts(o[i]));
					}
					System.err.println("]");
				}
			}

		}

	}

	static class Output implements Closeable, Flushable {
		public StringBuilder sb;
		public OutputStream os;
		public int BUFFER_SIZE;
		public boolean autoFlush;
		public String LineSeparator;

		public Output(OutputStream os) {
			this(os, 1<<16);
		}

		public Output(OutputStream os, int bs) {
			BUFFER_SIZE = bs;
			sb = new StringBuilder(BUFFER_SIZE);
			this.os = new BufferedOutputStream(os, 1<<17);
			autoFlush = false;
			LineSeparator = System.lineSeparator();
		}

		public void println(int i) {
			println(String.valueOf(i));
		}

		public void println(String s) {
			sb.append(s);
			println();
			if(autoFlush) {
				flush();
			}else if(sb.length()>BUFFER_SIZE >> 1) {
				flushToBuffer();
			}
		}

		public void println() {
			sb.append(LineSeparator);
		}

		private void flushToBuffer() {
			try {
				os.write(sb.toString().getBytes());
			}catch(IOException e) {
				e.printStackTrace();
			}
			sb = new StringBuilder(BUFFER_SIZE);
		}

		public void flush() {
			try {
				flushToBuffer();
				os.flush();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public void close() {
			flush();
			try {
				os.close();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

	}
}


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

public class Main{

	static int mod=(int)1e9+7;

	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		outer: while(ts-->0) {

			int n=in.nextInt();
			int a[]=in.readArray(n);

			int ans=n-1;

			for(int i=0; i<n; i++) {

				boolean valid_prefix=true;

				Set<Integer> set=new HashSet<>();

				for(int j=0; j<=i; j++) {

					if(set.contains(a[j])) {
						valid_prefix=false;
						break;
					}else {
						set.add(a[j]);
					}

				}

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

					if(set.contains(a[j])) break;
					set.add(a[j]);
					max_length_suffix++;

				}

				if(valid_prefix) ans=Math.min(ans, n-i-max_length_suffix-1);

			}

			out.println(ans);

		}
		out.close();

	}

/*********************************** UTILITY CODE BELOW **************************************/

	static int abs(int a) {
		return a>0 ? a : -a;
	}

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

	static long pow(long n, long m) {
		if(m==0) return 1;
		long temp=pow(n,m/2);
		long res=((temp*temp)%mod);
		if(m%2==0) return res;
		return (res*n)%mod;
	}

	static class Pair{
		int u, v;

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

		static void sort(Pair [] coll) {
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}

	}

	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static int [] array(int n, int value) {
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}

	static class Reader{

		BufferedReader br;
		StringTokenizer to;

		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}

		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());
				}catch(IOException e) {}

			}
			return to.nextToken();

		}

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

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

		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}

	}

	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}

}


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

public class Main{

	static int mod=(int)1e9+7;

	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		outer: while(ts-->0) {

			int n=in.nextInt();
			int a[]=in.readArray(n);

			int ans=n-1;

			for(int i=0; i<=n; i++) {  //i is the length of the prefix, it can be 0 or n

				boolean valid_prefix=true;

				Set<Integer> set=new HashSet<>();

				for(int j=0; j<i; j++) {

					if(set.contains(a[j])) {
						valid_prefix=false;
						break;
					}else {
						set.add(a[j]);
					}

				}

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

					if(set.contains(a[j])) break;
					set.add(a[j]);
					max_length_suffix++;

				}

				if(valid_prefix) ans=Math.min(ans, n-i-max_length_suffix);

			}

			out.println(ans);

		}
		out.close();

	}

/*********************************** UTILITY CODE BELOW **************************************/

	static int abs(int a) {
		return a>0 ? a : -a;
	}

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

	static long pow(long n, long m) {
		if(m==0) return 1;
		long temp=pow(n,m/2);
		long res=((temp*temp)%mod);
		if(m%2==0) return res;
		return (res*n)%mod;
	}

	static class Pair{
		int u, v;

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

		static void sort(Pair [] coll) {
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}

	}

	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static int [] array(int n, int value) {
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}

	static class Reader{

		BufferedReader br;
		StringTokenizer to;

		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}

		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());
				}catch(IOException e) {}

			}
			return to.nextToken();

		}

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

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

		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}

	}

	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}

}


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

public class Main{

	static int mod=(int)1e9+7;

	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		outer: while(ts-->0) {

			int n=in.nextInt();
			int a[]=in.readArray(n);

			int ans=Integer.MAX_VALUE;

			for(int i=0; i<n; i++) {

				boolean valid_prefix=true;

				Set<Integer> set=new HashSet<>();

				for(int j=0; j<=i; j++) {

					if(set.contains(a[j])) {
						valid_prefix=false;
						break;
					}else {
						set.add(a[j]);
					}

				}

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

					if(set.contains(a[j])) break;
					set.add(a[j]);
					max_length_suffix++;

				}

				if(valid_prefix) ans=Math.min(ans, n-i-max_length_suffix-1);

			}

			out.println(ans);

		}
		out.close();

	}

/*********************************** UTILITY CODE BELOW **************************************/

	static int abs(int a) {
		return a>0 ? a : -a;
	}

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

	static long pow(long n, long m) {
		if(m==0) return 1;
		long temp=pow(n,m/2);
		long res=((temp*temp)%mod);
		if(m%2==0) return res;
		return (res*n)%mod;
	}

	static class Pair{
		int u, v;

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

		static void sort(Pair [] coll) {
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}

	}

	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static void sort(long a[]) {
		ArrayList<Long> list=new ArrayList<>();
		for(long i: a) list.add(i);
		Collections.sort(list);
		for(int i=0; i<a.length; i++) a[i]=list.get(i);
	}

	static int [] array(int n, int value) {
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}

	static class Reader{

		BufferedReader br;
		StringTokenizer to;

		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}

		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());
				}catch(IOException e) {}

			}
			return to.nextToken();

		}

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

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

		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}

	}

	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}

}


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

// CODE JAM SHIT

public class Q2 {

    public static void main(String[] args) {

        InputReader in = new InputReader(true);
        PrintWriter out = new PrintWriter(System.out);
        int N =in.nextInt();
        int arr[]=new int[N+N];
        for(int i =0;i<N;i++) arr[i]=in.nextInt();
        for(int i=N;i<2*N;i++) arr[i]=arr[i%N];
        HashMap<Integer,Integer> set=new HashMap<>();
        int ans =0,l=0;
        for(int i =0;i<2*N;i++){
            if(set.size()==N){
                ans=N;
                break;
            }
            if(!set.containsKey(arr[i])){
                set.put(arr[i],1);
                if(l==0 || (l<N && i>=(N-1)))
                    ans=Math.max(ans,set.size());
            }else{
                while(l<i){
                    if(set.get(arr[l])==1)
                        set.remove(arr[l]);
                    else
                        set.put(arr[l],set.get(arr[l])-1);
                    l++;
                    if(!set.containsKey(arr[i])){
                        set.put(arr[i],1);
                        if(l==0 || (l<N && i>=(N-1)))
                            ans=Math.max(ans,set.size());
                        break;
                    }
                }
            }
        }
        out.println(N-ans);
        out.close();

    }

//    public static void main(String[] args) {
//
//        InputReader in = new InputReader();
//        PrintWriter out = new PrintWriter(System.out);
//
//        int t = in.nextInt(), l = 0;
//
//        while (t-- > 0) {
//
//            out.print("Case #" + (++l) + ": ");
//
//            int N = in.nextInt(), x = in.nextInt(), max = 0;
//            HashMap<Double, Integer> map = new HashMap<>();
//            double arr[] = new double[N];
//
//            for (int i = 0; i < N; i++) {
//                arr[i] = in.nextDouble();
//                map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
//                max = Math.max(max, map.get(arr[i]));
//            }
//
//            if (max >= x)
//                out.println(0);
//            else if (x == 2)
//                out.println(1);
//            else {
//
//                int flag = 0;
//                for (int i = 0; i < N; i++) {
//                    if (arr[i] % 2 == 0) {
//                        if (map.containsKey(arr[i] / 2))
//                            flag = 1;
//                    }
//                }
//
//                if (N == 1)
//                    out.println(2);
//                else if (flag == 1)
//                    out.println(1);
//                else{
//
//                    double min = Integer.MAX_VALUE;
//                    for (int i = 0; i < N; i++) {
//                        if (map.get(arr[i]) == 2) {
//                            min = Math.min(min, arr[i]);
//                        }
//                    }
//
//                    if (min < Integer.MAX_VALUE) {
//                        for (int i = 0; i < N; i++) {
//                            if (arr[i] > min)
//                                flag = 1;
//                        }
//                    }
//
//                    if (flag == 1 && max!=1)
//                        out.println(1);
//                    else
//                        out.println(2);
//                }
//            }
//        }
//        out.close();
//
//    }

    static class InputReader {
        InputStream is;

        public InputReader(boolean onlineJudge) {
            is = System.in;
        }

        byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        int readByte() {
            if (lenbuf == -1)
                throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

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

        char nextChar() {
            return (char) skip();
        }

        String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        String nextLine() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        char[][] nextMatrix(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++)
                map[i] = next(m);
            return map;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                int c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        long[] shuffle(long[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                long c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        long[] uniq(long[] arr) {
            Arrays.sort(arr);
            long[] rv = new long[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        int[] reverse(int[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        long[] reverse(long[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        int[] compress(int[] arr) {
            int n = arr.length;
            int[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        long[] compress(long[] arr) {
            int n = arr.length;
            long[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        void deepFillInt(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillInt(obj, val);
                }
            }
        }

        void deepFillLong(Object array, long val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof long[]) {
                long[] intArray = (long[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillLong(obj, val);
                }
            }
        }

    }
}


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

// CODE JAM SHIT

public class Q2 {

    public static void main(String[] args) {

        InputReader in = new InputReader(true);
        PrintWriter out = new PrintWriter(System.out);
        int N =in.nextInt();
        int arr[]=new int[N+N];
        for(int i =0;i<N;i++) arr[i]=in.nextInt();
        for(int i=N;i<2*N;i++) arr[i]=arr[i%N];
        HashMap<Integer,Integer> set=new HashMap<>();
        int ans =0,l=0;
        for(int i =0;i<2*N;i++){
            if(set.size()==N){
                ans=N;
                break;
            }
            if(!set.containsKey(arr[i])){
                set.put(arr[i],1);
                ans=Math.max(ans,set.size());
            }else{
                while(l<i){
                    if(set.get(arr[l])==1)
                        set.remove(arr[l]);
                    else
                        set.put(arr[l],set.get(arr[l])-1);
                    l++;
                    if(!set.containsKey(arr[i])){
                        set.put(arr[i],1);
                        ans=Math.max(ans,set.size());
                        break;
                    }
                }
            }
        }
        out.println(N-ans);
        out.close();

    }

//    public static void main(String[] args) {
//
//        InputReader in = new InputReader();
//        PrintWriter out = new PrintWriter(System.out);
//
//        int t = in.nextInt(), l = 0;
//
//        while (t-- > 0) {
//
//            out.print("Case #" + (++l) + ": ");
//
//            int N = in.nextInt(), x = in.nextInt(), max = 0;
//            HashMap<Double, Integer> map = new HashMap<>();
//            double arr[] = new double[N];
//
//            for (int i = 0; i < N; i++) {
//                arr[i] = in.nextDouble();
//                map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
//                max = Math.max(max, map.get(arr[i]));
//            }
//
//            if (max >= x)
//                out.println(0);
//            else if (x == 2)
//                out.println(1);
//            else {
//
//                int flag = 0;
//                for (int i = 0; i < N; i++) {
//                    if (arr[i] % 2 == 0) {
//                        if (map.containsKey(arr[i] / 2))
//                            flag = 1;
//                    }
//                }
//
//                if (N == 1)
//                    out.println(2);
//                else if (flag == 1)
//                    out.println(1);
//                else{
//
//                    double min = Integer.MAX_VALUE;
//                    for (int i = 0; i < N; i++) {
//                        if (map.get(arr[i]) == 2) {
//                            min = Math.min(min, arr[i]);
//                        }
//                    }
//
//                    if (min < Integer.MAX_VALUE) {
//                        for (int i = 0; i < N; i++) {
//                            if (arr[i] > min)
//                                flag = 1;
//                        }
//                    }
//
//                    if (flag == 1 && max!=1)
//                        out.println(1);
//                    else
//                        out.println(2);
//                }
//            }
//        }
//        out.close();
//
//    }

    static class InputReader {
        InputStream is;

        public InputReader(boolean onlineJudge) {
            is = System.in;
        }

        byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        int readByte() {
            if (lenbuf == -1)
                throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

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

        char nextChar() {
            return (char) skip();
        }

        String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        String nextLine() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        char[][] nextMatrix(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++)
                map[i] = next(m);
            return map;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                int c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        long[] shuffle(long[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                long c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        long[] uniq(long[] arr) {
            Arrays.sort(arr);
            long[] rv = new long[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        int[] reverse(int[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        long[] reverse(long[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        int[] compress(int[] arr) {
            int n = arr.length;
            int[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        long[] compress(long[] arr) {
            int n = arr.length;
            long[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        void deepFillInt(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillInt(obj, val);
                }
            }
        }

        void deepFillLong(Object array, long val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof long[]) {
                long[] intArray = (long[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillLong(obj, val);
                }
            }
        }

    }
}


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

// CODE JAM SHIT

public class Q2 {

    public static void main(String[] args) {

        InputReader in = new InputReader(true);
        PrintWriter out = new PrintWriter(System.out);
        int N =in.nextInt();
        int arr[]=new int[N+N];
        for(int i =0;i<N;i++) arr[i]=in.nextInt();
        for(int i=N;i<2*N;i++) arr[i]=arr[i%N];
        HashMap<Integer,Integer> set=new HashMap<>();
        int ans =0,l=0;
        for(int i =0;i<2*N;i++){
            if(set.size()==N){
                ans=N;
                break;
            }
            if(!set.containsKey(arr[i])){
                set.put(arr[i],1);
                if(l==0 || (l<N && i>=N))
                    ans=Math.max(ans,set.size());
            }else{
                while(l<i){
                    if(set.get(arr[l])==1)
                        set.remove(arr[l]);
                    else
                        set.put(arr[l],set.get(arr[l])-1);
                    l++;
                    if(!set.containsKey(arr[i])){
                        set.put(arr[i],1);
                        if(l==0 || (l<N && i>=N))
                            ans=Math.max(ans,set.size());
                        break;
                    }
                }
            }
        }
        out.println(N-ans);
        out.close();

    }

//    public static void main(String[] args) {
//
//        InputReader in = new InputReader();
//        PrintWriter out = new PrintWriter(System.out);
//
//        int t = in.nextInt(), l = 0;
//
//        while (t-- > 0) {
//
//            out.print("Case #" + (++l) + ": ");
//
//            int N = in.nextInt(), x = in.nextInt(), max = 0;
//            HashMap<Double, Integer> map = new HashMap<>();
//            double arr[] = new double[N];
//
//            for (int i = 0; i < N; i++) {
//                arr[i] = in.nextDouble();
//                map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
//                max = Math.max(max, map.get(arr[i]));
//            }
//
//            if (max >= x)
//                out.println(0);
//            else if (x == 2)
//                out.println(1);
//            else {
//
//                int flag = 0;
//                for (int i = 0; i < N; i++) {
//                    if (arr[i] % 2 == 0) {
//                        if (map.containsKey(arr[i] / 2))
//                            flag = 1;
//                    }
//                }
//
//                if (N == 1)
//                    out.println(2);
//                else if (flag == 1)
//                    out.println(1);
//                else{
//
//                    double min = Integer.MAX_VALUE;
//                    for (int i = 0; i < N; i++) {
//                        if (map.get(arr[i]) == 2) {
//                            min = Math.min(min, arr[i]);
//                        }
//                    }
//
//                    if (min < Integer.MAX_VALUE) {
//                        for (int i = 0; i < N; i++) {
//                            if (arr[i] > min)
//                                flag = 1;
//                        }
//                    }
//
//                    if (flag == 1 && max!=1)
//                        out.println(1);
//                    else
//                        out.println(2);
//                }
//            }
//        }
//        out.close();
//
//    }

    static class InputReader {
        InputStream is;

        public InputReader(boolean onlineJudge) {
            is = System.in;
        }

        byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        int readByte() {
            if (lenbuf == -1)
                throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

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

        char nextChar() {
            return (char) skip();
        }

        String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        String nextLine() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        char[][] nextMatrix(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++)
                map[i] = next(m);
            return map;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                int c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        long[] shuffle(long[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                long c = arr[i];
                arr[i] = arr[j];
                arr[j] = c;
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        long[] uniq(long[] arr) {
            Arrays.sort(arr);
            long[] rv = new long[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }

        int[] reverse(int[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        long[] reverse(long[] arr) {
            int l = 0, r = arr.length - 1;
            while (l < r) {
                arr[l] = arr[l] ^ arr[r];
                arr[r] = arr[l] ^ arr[r];
                arr[l] = arr[l] ^ arr[r];
                l++;
                r--;
            }
            return arr;
        }

        int[] compress(int[] arr) {
            int n = arr.length;
            int[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        long[] compress(long[] arr) {
            int n = arr.length;
            long[] rv = Arrays.copyOf(arr, n);
            rv = uniq(rv);
            for (int i = 0; i < n; i++) {
                arr[i] = Arrays.binarySearch(rv, arr[i]);
            }
            return arr;
        }

        void deepFillInt(Object array, int val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof int[]) {
                int[] intArray = (int[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillInt(obj, val);
                }
            }
        }

        void deepFillLong(Object array, long val) {
            if (!array.getClass().isArray()) {
                throw new IllegalArgumentException();
            }
            if (array instanceof long[]) {
                long[] intArray = (long[]) array;
                Arrays.fill(intArray, val);
            } else {
                Object[] objArray = (Object[]) array;
                for (Object obj : objArray) {
                    deepFillLong(obj, val);
                }
            }
        }

    }
}


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

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

        // Try each prefix that does not contain any duplicates.
        // Extend the suffix to the longest possible.
        int n = sc.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int result = n;
        // Expand a prefix of unique vals only.
        Set<Integer> prefixes = new HashSet<>();

        for (int i = 0; i < n; i++) {
            Set<Integer> suffixes = new HashSet<>();
            int min = n;

            for (int j = n-1; j >= i; j--) {
                int sVal = arr[j];

                if (prefixes.contains(sVal) || suffixes.contains(sVal)) {
                    break;
                }

                min = j;
                suffixes.add(sVal);
            }

            result = Math.min(result, min - i);

            int val = arr[i];

            // Expanding prefix no longer is unique.
            if (prefixes.contains(val)) {
                break;
            }
            prefixes.add(val);
        }

        System.out.println(result);
    }
}


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

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

        // Try each prefix that does not contain any duplicates.
        // Extend the suffix to the longest possible.
        int n = sc.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int result = n;
        // Expand a prefix of unique vals only.
        Set<Integer> prefixes = new HashSet<>();

        for (int i = 0; i < n; i++) {
            int val = arr[i];

            // Expanding prefix no longer is unique.
            if (prefixes.contains(val)) {
                break;
            }
            prefixes.add(val);

            Set<Integer> suffixes = new HashSet<>();
            int min = n;

            for (int j = n-1; j > i; j--) {
                int sVal = arr[j];

                if (prefixes.contains(sVal) || suffixes.contains(sVal)) {
                    break;
                }

                min = j;
                suffixes.add(sVal);
            }

            result = Math.min(result, min - i - 1);
        }

        System.out.println(result);
    }
}


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

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

        int n = sc.nextInt();
        Map<Integer, Integer> counts = new HashMap<>();

        int[] arr = new int[n];
        int uniqueNums = 0;

        for (int i = 0; i < n; i++) {
            int val = sc.nextInt();

            counts.put(val, counts.getOrDefault(val, 0) + 1);
            if (counts.get(val) == 1) {
                uniqueNums++;
            }

            arr[i] = val;
        }

        Map<Integer, Integer> currCounts = new HashMap<>();
        int currMatching = 0; // number of digits that is >= counts

        // For digits with 1 occurrence, we don't need to remove any.
        for (int val : counts.keySet()) {
            if (counts.get(val) == 1) {
                currMatching++;
            }
        }

        // Every number is unique, so answer is 0.
        if (currMatching == uniqueNums) {
            System.out.println(0);
            return;
        }

        int startIndex = 0;
        int result = n;

        for (int i = 0; i < n; i++) {
            int val = arr[i];

            currCounts.put(val, currCounts.getOrDefault(val, 0) + 1);
            if (currCounts.get(val) == counts.get(val) - 1) {
                currMatching++;
            }

            if (currMatching == uniqueNums) {
                while (currMatching == uniqueNums) {
                    result = Math.min(result, i - startIndex + 1);

                    int front = arr[startIndex++];
                    if (currCounts.get(front) == counts.get(val) - 1) {
                        currMatching--;
                    }
                    currCounts.put(front, currCounts.get(front)-1);
                }
            }
        }

        System.out.println(result);
    }
}


import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int len = n;
        for (int j = 0; j < n; j++) {
            a[j] = sc.nextInt();
        }

        HashMap<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int start = 1;
        int end = n;
        for (int i = 0; i < n; i++) {
            start = 1;
            end=n;
            for (int j = 0; j < i; j++) {

                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) > 1) {
                    start = 0;
                    break;
                }
            }

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

                //System.out.println(cnt);
                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) == 1) {
                    end = j;
                } else break;
            }
            if (start == 1) {
                len = Math.min(len, end - i);
            }

            cnt.clear();

        }
        System.out.println(len);
    }
}


import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int len = n;
        for (int j = 0; j < n; j++) {
            a[j] = sc.nextInt();
        }

        HashMap<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int start = 1;
        int end = n;
        for (int i = 0; i < n; i++) {
            len=n;
            start = 1;
            end=n;
            for (int j = 0; j < i; j++) {

                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) > 1) {
                    start = 0;
                    break;
                }
            }

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

                //System.out.println(cnt);
                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) == 1) {
                    end = j;
                    //System.out.println(end);
                } else {
                    break;
                }
            }
            if (start == 1) {
                len = Math.min(len, end - i);
            }

            cnt.clear();

        }
        System.out.println(len);
    }
}


import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int len = n;
        for (int j = 0; j < n; j++) {
            a[j] = sc.nextInt();
        }

        HashMap<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int start = 1;
        int end = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            start = 1;
            for (int j = 0; j < i; j++) {

                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) > 1) {
                    start = 0;
                    break;
                }
            }

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

                //System.out.println(cnt);
                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) == 1) {
                    end = j;
                } else break;
            }
            if (start == 1) {
                len = Math.min(len, end - i);
            }

            cnt.clear();

        }
        System.out.println(len);
    }
}


import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int len = n;
        for (int j = 0; j < n; j++) {
            a[j] = sc.nextInt();
        }

        HashMap<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int start = 1;
        int end = n;
        for (int i = 0; i < n; i++) {
            start = 1;
            for (int j = 0; j < i; j++) {

                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) > 1) {
                    start = 0;
                    break;
                }
            }

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

                //System.out.println(cnt);
                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) == 1) {
                    end = j;
                } else break;
            }
            if (start == 1) {
                len = Math.min(len, end - i);
            }

            cnt.clear();

        }
        System.out.println(len);
    }
}


import java.util.HashMap;
import java.util.Scanner;

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

        int n = sc.nextInt();

        int[] a = new int[n];
        int len = n;
        for (int j = 0; j < n; j++) {
            a[j] = sc.nextInt();
        }

        HashMap<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int start = 1;
        int end = n;
        for (int i = 0; i < n; i++) {
            start = 1;
            end=n;
            for (int j = 0; j < i; j++) {

                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) > 1) {
                    start = 0;
                    break;
                }
            }

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

                //System.out.println(cnt);
                if(!cnt.containsKey(a[j])){
                    cnt.put(a[j],1);
                }else {
                    cnt.put(a[j], cnt.get(a[j]) + 1);
                }
                if (cnt.get(a[j]) == 1) {
                    end = j;
                    //System.out.println(end);
                } else {
                    break;
                }
            }
            if (start == 1) {
                len = Math.min(len, end - i);
            }

            cnt.clear();

        }
        System.out.println(len);
    }
}


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

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings({"Duplicates", "ConstantConditions"})
    void solve() throws Exception
    {
        int n = sc.nextInt();
        /*read int arr a of size n*/ int[] a = new int[n]; for (int I = 0; I < n; I++) a[I] = sc.nextInt();
        int ans = n;
        outer: for (int left = 0; left < n; left++)
        {
            TreeSet<Integer> first = new TreeSet<>();
            for (int i = 0; i < left; i++)
                if (first.contains(a[i]))
                    continue outer;
                else first.add(a[i]);
//            System.out.println(first);
            TreeSet<Integer> mid = new TreeSet<>();
            for (int i = left; i < n; i++)
                if (mid.contains(a[i]))
                {
                    ans = min(ans, n - (i - 1 - left + 1));
                    continue outer;
                }
                else mid.add(a[i]);
//            System.out.println(left + "gay");
            ans = min(ans, left);
        }
        System.out.println(ans);
    }

    long pow(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t);
        return (((x*t))*t);
    }
    long powmod(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t)%MOD;
        return (((x*t)%MOD)*t)%MOD;
    }

    StringBuilder ANS = new StringBuilder();
    void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
    void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}


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

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings({"Duplicates", "ConstantConditions"})
    void solve() throws Exception
    {
        int n = sc.nextInt();
        /*read int arr a of size n*/ int[] a = new int[n]; for (int I = 0; I < n; I++) a[I] = sc.nextInt();
        int ans = n;
        outer: for (int left = 0; left < n; left++)
        {
            TreeSet<Integer> remain = new TreeSet<>();
            for (int i = 0; i < left; i++)
                if (remain.contains(a[i])) continue outer;
                else remain.add(a[i]);
            int ptr = n - 1;
            while (ptr >= left && !remain.contains(a[ptr]))
            {
                remain.add(a[ptr]);
                ptr--;
            }
            ans = min(ans, ptr - left + 1);
        }
        System.out.println(ans);
    }

    long pow(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t);
        return (((x*t))*t);
    }
    long powmod(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t)%MOD;
        return (((x*t)%MOD)*t)%MOD;
    }

    StringBuilder ANS = new StringBuilder();
    void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
    void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}


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

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings({"Duplicates", "ConstantConditions"})
    void solve() throws Exception
    {
        int n = sc.nextInt();
        /*read int arr a of size n*/ int[] a = new int[n]; for (int I = 0; I < n; I++) a[I] = sc.nextInt();
        int ans = n;
        outer: for (int left = 0; left < n; left++)
        {
            TreeSet<Integer> mid = new TreeSet<>();
            for (int i = left; i < n; i++)
                if (mid.contains(a[i]))
                    continue outer;
                else
                {
                    mid.add(a[i]);
                    //[left, i] fine
                    ans = min(ans, n - (i - left + 1));
                }
            ans = min(ans, left);
        }
        System.out.println(ans);
    }

    long pow(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t);
        return (((x*t))*t);
    }
    long powmod(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t)%MOD;
        return (((x*t)%MOD)*t)%MOD;
    }

    StringBuilder ANS = new StringBuilder();
    void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
    void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}


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

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings({"Duplicates", "ConstantConditions"})
    void solve() throws Exception
    {
        int n = sc.nextInt();
        /*read int arr a of size n*/ int[] a = new int[n]; for (int I = 0; I < n; I++) a[I] = sc.nextInt();
        int ans = n;
        outer: for (int left = 0; left < n; left++)
        {
            TreeSet<Integer> mid = new TreeSet<>();
            for (int i = left; i < n; i++)
                if (mid.contains(a[i]))
                {
                    ans = min(ans, n - (i - 1 - left + 1));
                    continue outer;
                }
                else mid.add(a[i]);
            ans = min(ans, left);
        }
        System.out.println(ans);
    }

    long pow(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t);
        return (((x*t))*t);
    }
    long powmod(long x, long y){
        if(y==0) return 1L;
        long t=powmod(x,y/2);
        if (y%2==0) return (t*t)%MOD;
        return (((x*t)%MOD)*t)%MOD;
    }

    StringBuilder ANS = new StringBuilder();
    void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
    void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}


/*
				C++
				encoding: UTF-8
				Modified: <26/Aug/2019 12:05:05 AM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define         ll                     long long
#define         ve                     vector
#define         pb                     push_back
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (int i = s ; i > n ; --i)

void pr () {
    cout << "\n";
}

template < typename T, typename... ARGS > void pr (const T& t, ARGS... args) {
    cout << t << " ";
    pr (args...);
}

// clang-format on

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table< int, int, hash< int > > ht;

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	int arr[n + 1];
	ht tmp;
	int flag = 1;
	int cnt = 0;
	fr (i, 1, n + 1) {
		int x;
		cin >> x;
		if (tmp.find (x) != tmp.end ()) {
			arr[i] = tmp[x];
		} else {
			cnt++;
			arr[i] = cnt;
			tmp[x] = cnt;
		}

		tmp[arr[i]]++;
		if (tmp[arr[i]] > 1) flag = 0;
	}
	if (flag) {
		pr (0);
		return 0;
	}

	int ans = n - 1;
	fr (i, 1, n + 1) {
		int low = i, high = n + 1;
		int cnt = 0;
		while (low <= high) {
			int mid = (low + high + 1) / 2;

			ht mp;
			fr (j, 1, i) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}
			fr (j, mid + 1, n + 1) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}

			int flag = 1;
			for (auto x : mp) {
				if (x.ss > 1) {
					flag = 0;
					break;
				}
			}

			if (flag) {
				high = mid - 1;
				ans = min (ans, mid - i + 1);
				// pr (low, high, mid, i, ans);
			} else
				low = mid + 1;
		}
	}
	pr (ans);
	return 0;
}


/*
				C++
				encoding: UTF-8
				Modified: <25/Aug/2019 11:56:05 PM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define         ll                     long long
#define         ve                     vector
#define         pb                     push_back
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (int i = s ; i > n ; --i)

void pr () {
    cout << "\n";
}

template < typename T, typename... ARGS > void pr (const T& t, ARGS... args) {
    cout << t << " ";
    pr (args...);
}

// clang-format on

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table< int, int, hash< int > > ht;

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	int arr[n + 1];
	ht tmp;
	int flag = 1;
	fr (i, 1, n + 1) {
		cin >> arr[i];
		tmp[arr[i]]++;
		if (tmp[arr[i]] > 1) flag = 0;
	}
	if (flag) {
		pr (0);
		return 0;
	}

	int ans = n - 1;
	fr (i, 1, n + 1) {
		int low = i, high = n + 1;
		int cnt = 0;
		while (low <= high) {
			int mid = (low + high + 1) / 2;

			ht mp;
			fr (j, 1, i) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}
			fr (j, mid + 1, n + 1) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}

			int flag = 1;
			for (auto x : mp) {
				if (x.ss > 1) {
					flag = 0;
					break;
				}
			}

			if (flag) {
				high = mid - 1;
				ans = min (ans, mid - i + 1);
				// pr (low, high, mid, i, ans);
			} else
				low = mid + 1;
		}
	}
	pr (ans);
	return 0;
}


/*
				C++
				encoding: UTF-8
				Modified: <26/Aug/2019 12:00:21 AM>

				✪ H4WK3yE乡
				Mohd. Farhan Tahir
				Indian Institute Of Information Technology (IIIT), Gwalior
*/

#include <bits/stdc++.h>
#ifdef LOCAL_PROJECT
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define         ll                     long long
#define         ve                     vector
#define         pb                     push_back
#define         endl                   "\n";
#define         ff                     first
#define         ss                     second
#define         pii                    pair<int, int>
#define         len(v)                 int(v.size())
#define         all(v)                 v.begin(), v.end()
#define         reset(a, b)            memset(a, b, sizeof(a));
#define         fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define         dfr(i, s, n)           for (int i = s ; i > n ; --i)

void pr () {
    cout << "\n";
}

template < typename T, typename... ARGS > void pr (const T& t, ARGS... args) {
    cout << t << " ";
    pr (args...);
}

// clang-format on

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table< int, int, hash< int > > ht;

signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	int arr[n + 1];
	ht tmp;
	int flag = 1;
	int cnt = 0;
	fr (i, 1, n + 1) {
		int x;
		cin >> x;
		if (tmp.find (x) == tmp.end ()) cnt++;
		arr[i] = cnt;
		tmp[arr[i]]++;
		if (tmp[arr[i]] > 1) flag = 0;
	}
	if (flag) {
		pr (0);
		return 0;
	}

	int ans = n - 1;
	fr (i, 1, n + 1) {
		int low = i, high = n + 1;
		int cnt = 0;
		while (low <= high) {
			int mid = (low + high + 1) / 2;

			ht mp;
			fr (j, 1, i) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}
			fr (j, mid + 1, n + 1) {
				mp[arr[j]]++;
				if (mp[arr[j]] > 1) break;
			}

			int flag = 1;
			for (auto x : mp) {
				if (x.ss > 1) {
					flag = 0;
					break;
				}
			}

			if (flag) {
				high = mid - 1;
				ans = min (ans, mid - i + 1);
				// pr (low, high, mid, i, ans);
			} else
				low = mid + 1;
		}
	}
	pr (ans);
	return 0;
}


#include<bits/stdc.h>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1];
        vector <int> v;

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=1;
            int max=0;
            for(int j=i*2;j<=n;)
            {
                if(max<a[j]&&max!=0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else if(a[i]<a[j]&&max==0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else
                {
                     v.push_back(count);
                     j=(i*2)+k;
                     count=1;
                     max=0;
                     k++;

                }

            }

            v.push_back(count);

        }

        sort(v.begin(),v.end());

        int k2=v.size();
        cout<<v[k2-1]<<endl;
    }

}


#include<bits/stdc.h>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1];
        vector <int> v;

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=1;
            int max=0;
            for(int j=i*2;j<=n;)
            {
                if(max<a[j]&&max!=0)
                {
                    max=a[j];
                    count++;
                    j=j*2;
                }

                else if(a[i]<a[j]&&max==0)
                {
                    max=a[j];
                    count++;
                    j=j*2;
                }

                else
                {
                     v.push_back(count);
                     j=(i*2)+k;
                     count=1;
                     max=0;
                     k++;

                }

            }

            v.push_back(count);

        }

        sort(v.begin(),v.end());

        int k2=v.size();
        cout<<v[k2-1]<<endl;
    }

}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1],a1[n];

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=2;
            int max;
            for(int j=i*2;j<=n;)
            {
                if(a[i]<a[j]&&(j==(i*2)))
                {
                    max=a[j];
                    count++;
                    j=j*k;
                }
                else if(max<a[j])
                {
                    max=a[j];
                    count++;
                    j=j*k;
                }
                else
                {
                     j++;
                     k++;
                }

            }

            a1[i-1]=count;

        }

        sort(a1,a1+n);

        cout<<a1[n-1]<<endl;
    }

}


#include<bits/stdc++.h>

#define int long long int
using namespace std;

signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;

        int ar[n+1],dp[n+1];
        for(int i=1;i<n+1;i++)
        {
            cin>>ar[i];
            dp[i]=1;
        }
        int ans=1;
        for(int i=2;i<n+1;i++)
        {
            int mx=0;
            for(int j=1;j*j<=i;j++)
            { if(i%j==0)
             {
                {
                    int k1=j;
                    int k2=i/j;

                    if(ar[k1]<ar[i])
                    {
                        mx=std::max(mx,dp[k1]);
                    }
                    if(ar[k2]<ar[i])
                    {
                        mx=std::max(mx,dp[k2]);
                    }

                 }
              }
            }

            dp[i]+=mx;
            ans=std::max(ans,dp[i]);

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1];
        vector <int> v;

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=1;
            int max=0;
            for(int j=i*2;j<=n;)
            {
                if(max<a[j]&&max!=0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else if(a[i]<a[j]&&max==0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else
                {
                     v.push_back(count);
                     j=(i*2)+k;
                     count=1;
                     max=0;
                     k++;

                }

            }

            v.push_back(count);

        }

        sort(v.begin(),v.end());

        int k2=v.size();
        cout<<v[k2-1]<<endl;
    }

}


#include<iostream>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1],a1[n];

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1;
            int k=2;
            for(int j=i*k;j<=n;)
            {
                if(a[i]<a[j]&&j%i==0)
                {
                    count++;
                     k++;
                     j=j*k;
                }
                else
                {
                     j++;
                }

            }

            a1[i-1]=count;

        }

        sort(a1,a1+n);

        cout<<a1[n-1]<<endl;
    }

}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1],a1[n];

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1;
            int k=2;
            for(int j=i*k;j<=n;)
            {
                if(a[i]<a[j]&&j%i==0)
                {
                    count++;
                     k++;
                     j=j*k;
                }
                else
                {
                     j++;
                }

            }

            a1[i-1]=count;

        }

        sort(a1,a1+n);

        cout<<a1[n-1]<<endl;
    }

}


#include<bits/stdc++.h>

#define int long long int
using namespace std;

signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;

        int ar[n+1],dp[n+1];
        for(int i=1;i<n+1;i++)
        {
            cin>>ar[i];
            dp[i]=1;
        }
        int ans=1;
        for(int i=2;i<n+1;i++)
        {
            int mx=0;
            for(int j=1;j*j<=i;j++)

            {
                int k1=j;
                int k2=i/j;

                if(ar[k1]<ar[i])
                {
                    mx=std::max(mx,dp[k1]);
                }
                if(ar[k2]<ar[i])
                {
                    mx=std::max(mx,dp[k2]);
                }

            }
            dp[i]+=mx;
            ans=std::max(ans,dp[i]);

        }
        cout<<ans<<endl;

    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1];
        vector <int> v;

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=1;
            int max=0;
            for(int j=i*2;j<=n;)
            {
                if(max<a[j]&&max!=0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else if(a[i]<a[j]&&max==0)
                {
                    max=a[j];
                    count++;
                    j=j+i;
                }

                else
                {
                     v.push_back(count);
                     j=j+i;
                     count=1;
                     max=0;
                     k++;

                }

            }

            v.push_back(count);

        }

        sort(v.begin(),v.end());

        int k2=v.size();
        cout<<v[k2-1]<<endl;
    }

}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int t ;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+1],a1[n];

        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }

        for(int i=1;i<=n;i++)
        {
            int count=1,k=1;
            int max=0;
            for(int j=i*2;j<=n;)
            {
                if(max<a[j]&&max!=0)
                {
                    max=a[j];
                    count++;
                    j=j*2;
                }

                else if(a[i]<a[j]&&max==0)
                {
                    max=a[j];
                    count++;
                    j=j*2;
                }

                else
                {
                     j=(i*2)+k;
                     count=1;
                     max=0;
                     k++;

                }

            }

            a1[i-1]=count;

        }

        sort(a1,a1+n);

        cout<<a1[n-1]<<endl;
    }

}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 12/05/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <math.h>
#define ll long long
using namespace std;
vector<ll int> fac;
ll int N;
vector<ll int> v;map<ll int, ll int > mp;
ll int final_try(ll int n,ll int tv){
    ll int i,mx=tv;
    if (mp[n]!=0) {
        return mx;
    }
    if ((n*2)>N) {
        //cout<<"he"<<endl;
       return tv;

    }
    for (i=n*2; i<=N; i=i+n) {
        if ((i)>N) {
            //cout<<"he"<<endl;
            return tv;

        }else{
            if (v[n]<v[i]) {
                //cout<<"me"<<endl;
                mx=max(mx, final_try(i, tv+1));
            }
        }
    }
    mp[n]=mx;
   // cout<<"ke"<<endl;
    return mx;
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,M,a,b,c;
    cin>>T;
    while (T--) {
        cin>>N;
        v.clear();
        //vector<pair<ll int, ll int>> vp;
        v.push_back(0);
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            //vp.push_back({a,i+1});
        }
        //sort(vp.begin(), vp.end());
        mp.clear();

        ll int mx=1;
        for (i=1; i<=N; i++) {
            mx=max(mx, final_try(i,1));
        }
        cout<<mx<<endl;
    }
    return 0;
}
/*
 1
 20
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 */


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 12/05/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <math.h>
#define ll long long
using namespace std;
vector<ll int> fac;
ll int N;
vector<ll int> v;map<ll int, ll int > mp;
ll int final_try(ll int n,ll int tv){
    ll int i,mx=tv;
    if (mp[n]!= 0 ) {
        return mx;
    }
    if ((n*2)>N) {
        //cout<<"he"<<endl;
       return tv;

    }
    for (i=n*2; i<=N; i=i+n) {
        if ((i)>N) {
            //cout<<"he"<<endl;
            return tv;

        }else{
            if (v[n]<v[i]) {
                //cout<<"me"<<endl;
                mx=max(mx, final_try(i, tv+1));
            }
        }
    }
    mp[n]=mx;
   // cout<<"ke"<<endl;
    return mx;
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,M,a,b,c;
    cin>>T;
    while (T--) {
        cin>>N;
        v.clear();
        //vector<pair<ll int, ll int>> vp;
        v.push_back(0);
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            //vp.push_back({a,i+1});
        }
        //sort(vp.begin(), vp.end());
        mp.clear();

        ll int mx=1;
        for (i=1; i<=N; i++) {
            mp.clear();
            mx=max(mx, final_try(i,1));
        }
        cout<<mx<<endl;
    }
    return 0;
}
/*
 1
 20
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 */


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 12/05/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <math.h>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,N,T,M,a,b,c;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        //vector<pair<ll int, ll int>> vp;
        v.push_back(0);
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            //vp.push_back({a,i+1});
        }
        /*sort(vp.begin(), vp.end());
        ll int ans=0,ist=1,num=v[1];
        for (i=1; i<=N; i++) {
            if (vp[i].second==1) {
                ist=i;
                break;
            }
        }
        for (i=ist; i<=N; i++) {
            if (vp[i].first>=num) {
                ans+=1;
            }
        }*/
        j=2;
        ll int ans=1,ta=0,pj=0;
        while ((N/j)>0) {
            ta=1;
            pj=j;
            for (i=j*2; i<=N; i=i+j) {
                if (v[pj]<v[i]) {
                    ta+=1;
                }
                pj=i;
            }
            if (v[1]<v[j] && ta>1) {
                ta+=1;
            }
            j+=1;
            ans=max(ans,ta);
        }
        cout<<ans<<endl;
    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 12/05/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <math.h>
#define ll long long
using namespace std;
vector<ll int> fac;
ll int N;
vector<ll int> v;map<ll int, ll int > mp;
ll int final_try(ll int n,ll int tv){
    ll int i,mx=tv;
    if (mp[n] != 0 ) {
        return mx;
    }
    if ((n*2)>N) {
        //cout<<"he"<<endl;
       return tv;

    }mp[n]=mx;
    for (i=n*2; i<=N; i=i+n) {
        if ((i)>N) {
            //cout<<"he"<<endl;
            return tv;

        }else{
            if (v[n]<v[i]) {
                //cout<<"me"<<endl;
                mx=max(mx, final_try(i, tv+1));
            }
        }
    }
    mp[n]=mx;
   // cout<<"ke"<<endl;
    return mx;
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,M,a,b,c;
    cin>>T;
    while (T--) {
        cin>>N;
        v.clear();
        //vector<pair<ll int, ll int>> vp;
        v.push_back(0);
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            //vp.push_back({a,i+1});
        }
        //sort(vp.begin(), vp.end());
        mp.clear();

        ll int mx=1;
        for (i=1; i<=N; i++) {
            mp.clear();
            mx=max(mx, final_try(i,1));
        }
        cout<<mx<<endl;
    }
    return 0;
}
/*
 1
 20
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 */


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 12/05/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <math.h>
#define ll long long
using namespace std;
vector<ll int> fac;
ll int N;
vector<ll int> v;map<ll int, ll int > mp;
ll int final_try(ll int n,ll int tv){
    ll int i,mx=tv;

    if ((n*2)>N) {
        //cout<<"he"<<endl;
       return tv;

    }mp[n]=mx;
    for (i=n*2; i<=N; i=i+n) {
        if ((i)>N) {
            //cout<<"he"<<endl;
            return tv;

        }else{
            if (v[n]<v[i]) {
                //cout<<"me"<<endl;
                mx=max(mx, final_try(i, tv+1));
            }
        }
    }
    mp[n]=mx;
   // cout<<"ke"<<endl;
    return mx;
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,M,a,b,c;
    cin>>T;
    while (T--) {
        cin>>N;
        v.clear();
        //vector<pair<ll int, ll int>> vp;
        v.push_back(0);
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            //vp.push_back({a,i+1});
        }
        //sort(vp.begin(), vp.end());
        mp.clear();

        ll int mx=1;
        for (i=1; i<=N; i++) {
            //mp.clear();
            if (mp[i]==0) {
                mx=max(mx, final_try(i,1));
            }

        }
        cout<<mx<<endl;
    }
    return 0;
}
/*
 1
 20
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 */