using System; using System.Linq; class Program { static void Main() { int ans = 0; int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); for (int i = n; 0 <= i; i--) { int ai = a.IndexOf(i); for (int j = i - 1; 0 <= j; j--) { if (ai < a.IndexOf(j)) { ans = Math.Max(ans, j); break; } } } Console.WriteLine(ans); } }