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 - ind[a] ans = max(ans, length) left = ind[a] + 1 ind[a] = i ans = max(ans, n-left) print(ans)