using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; if (n == 1) { WriteLine(0); return; } var count = new int[n / 2]; foreach (var ai in a) if (ai < count.Length) ++count[ai]; var tmp = 0; for (var i = 0; i < count.Length; ++i) { tmp += Math.Max(0, 2 - count[i]); if (tmp >= 2) { WriteLine(i); return; } } WriteLine(count.Length); } }