N = int(input()) A = list(map(int, input().split())) ans = 0 L = 0 R = -1 q = set() for a in A: if a not in q: q.add(a) R += 1 else: ans = max(ans, R-L+1) while A[L] != a: q.remove(A[L]) L += 1 L += 1 R += 1 ans = max(ans, R-L+1) print(ans)