n=int(input()) ns=list(map(int,input().split())) dic={} s=set() cnt=0 ans=0 r=0 for i in range(n): if ns[i] not in dic: dic[ns[i]] = 1 cnt += 1 ans=max(ans,cnt) else: dic[ns[i]] += 1 s.add(ns[i]) while s: if ns[r] in s: dic[ns[r]] -= 1 s=set() r+=1 else: dic[ns[r]] -= 1 if dic[ns[r]] == 0: del dic[ns[r]] r+=1 cnt = (i+1) - r print(ans)