n = int(input()) A = list(map(int,input().split())) ans = 0 left = 0 ind = {} for i,a in enumerate(A): if a not in ind: ind[a] = i else: length = i - left ans = max(ans, length) left = max(left, ind[a]+1) ind[a] = i ans = max(ans, n-left) print(ans)