-- yukicoder My Practice -- author: Leonardone @ NEETSDKASU n = io.read() gi = io.read():gmatch('%d+') mx = 0 ans = 0 for i = 1, n do v = tonumber(gi()) mx = math.max(v, mx) if v > ans and v < mx then ans = v end end print(ans)