N=int(input()) A=list(map(int,input().split())) myset =set() front = 0 back = 0 answer = 1 while front!=N: if A[front] in myset: #print(A[front]) tmp=front-back-1 answer = answer if answer>tmp else tmp for i in range(back,front): if A[i]==A[front]: back=i+1 break myset.remove(A[i]) else: myset.add(A[front]) front=front+1 #print(answer) #print(back,front) tmp=front-back answer = answer if answer>tmp else tmp print(answer)