n = int(input()) a = list(map(int,input().split())) num = [False] * 1000001 length = 0 start = 0 best_s = 0 best_l = 0 i = 0 while i < n: if not num[a[i]]: num[a[i]] = True length += 1 i += 1 else: if start >= n: break while start < i and a[start] != a[i]: num[a[i]] = False start += 1 start += 1 length = i - start + 1 i += 1 best_l = max(best_l, length) if best_l == length: best_s = start print(best_l)