N = gets.to_i A = gets.split.map(&:to_i) counter = Hash.new(0) left = 0 right = 0 counter[A[0]] += 1 ans = 1 while left <= right if right == N - 1 counter[A[left]] -= 1 left += 1 elsif counter[A[right]] >= 2 counter[A[left]] -= 1 left += 1 else right += 1 counter[A[right]] += 1 end if counter[A[right]] <= 1 len = right - left + 1 ans = len if ans < len end end puts ans