void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.split.to!(int[]);

    int[] b = a.dup;
    b[] -= 1;
    int[] c = a.dup;
    c[] += 1;
    a ~= b ~ c;

    auto g = a.sort!"a < b".group.array;
    g.sort!((x, y) => x[1] > y[1]);

    g[0][1].writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;