/**
 * Created by IntelliJ IDEA.
 * User: m09kaa3
 * Date: Sep 30, 2009
 * Time: 7:39:06 PM
 * To change this template use File | Settings | File Templates.
 */
import java.io.*;
import java.util.*;
public class Stive {
    public static void main(String[] args) throws Exception{
        Scanner s=new Scanner (new File("buy.in"));
        PrintWriter p=new PrintWriter(new File("buy.out"));
        int n= s.nextInt();
        if (n<3) {
            p.print(-1);
        }
        else{
            int a= 1001;
            int b= 1001;
            int c= 1001;
            if (b>a) {int t= a;a=b;b=t;}
            if (c>a)  {int t=a;a=c;c=t;}
            if (c>b)  {int t=b;b=c;c=t;}
            for(int i=1;i<=n;i++){
                int d= s.nextInt();
                if(d!=c  && d!=b && d<a) {
                    a=d;
                    if (b>a) {int t= a;a=b;b=t;}
            if (c>a)  {int t=a;a=c;c=t;}
            if (c>b)  {int t=b;b=c;c=t;}
                }
            }
            p.print(a);
        }
        p.close();
    }
}
