from collections import defaultdict N = int(input()) A = list(map(int, input().split())) ans = 0 counter = defaultdict(int) r = 0 for l in range(N): while r < N and (not counter[A[r]]): counter[A[r]] += 1 r += 1 ans = max(ans, r-l) counter[l] -= 1 print(ans)