using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace Application { class MainClass { public static void Main (string[] args) { var N = readInt (); var A = readInts (' '); var s = new Searcher (); var l = 0; while (l < N) { l = s.LonguestSeq (A, l); } writeLine (s.Longest); } public class Searcher { public int Longest = 0; private Queue distinct = new Queue (); public int LonguestSeq (int[] A, int l) { var i = l + distinct.Count; for (; i < A.Length && !distinct.Contains (A [i]); i++) { distinct.Enqueue (A [i]); } this.Longest = Math.Max (distinct.Count, this.Longest); while (true) { l++; if (distinct.Count == 0) break; if (A.Length <= i) break; if (A [i] == distinct.Dequeue ()) break; } return l; } } static void writeLine (object o) { System.Console.WriteLine (o.ToString ()); } static string readItem () { return readItems (' ') [0]; } static String[] readItems (char c) { return System.Console.ReadLine ().Split (c); } static int readInt () { return readInts (' ') [0]; } static int[] readInts (char c) { return readItems (c).Select (x => int.Parse (x)).ToArray (); } } }