import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = sc.nextInt(); } int max = 0; Map map = new HashMap(); int left = 0; for(int i = 0; i < N; i++){ if(map.containsKey(arr[i])){ max = Math.max(max, i - left); left = map.get(arr[i]) + 1; } map.put(arr[i], i); } max = Math.max(max, N - left); System.out.println(max); } }