import java.util.Scanner;
public class Main{
static final int N = 100010;
static int[] q = new int[N];
static int[] s = new int[N];
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0; i < n; i++) q[i] = sc.nextInt();
int res = 0;
for(int i = 0, j = 0; i < n; i++){
s[q[i]]++;
while(j < i && s[q[i]] > 1) s[q[j++]]--;
res = Math.max(res, i - j + 1);
}
System.out.println(res);
}
}