import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class exam_session
{
    static ArrayList<Integer> b;
    static int a1[],a2[],count[],n,z,res=0,p;
    static void rec(int x)
    {
        if(b.contains(x))
        {
            int y=b.indexOf(x);
            if(count[y]==1)
            {
                //System.out.println("-1");
                res=-1;
                return;
            }
            count[y]++;
            if(a1[y]==x)
                z=a2[y];
            else
                z=a1[y];
            if(z>p)
            {
                rec(p);
                if(res==-1)
                    rec(z);
            }
            else
            {
                rec(z);
                if(res==-1)
                    rec(p);
            }
        }
        else
        {
            //System.out.print(x+" ");
            b.add(x);
            //System.out.println(b);
            res=0;
            return;
        }
    }
    public static void main(String[] args)
    {
        Scanner sc =new Scanner(System.in);
        n=sc.nextInt();
        //int res=0;
        a1=new int[n];
        a2=new int[n];
        count=new int[n];
        b=new ArrayList<Integer>();
        for(int i=0;i<n;i++)
        {
            a1[i]=sc.nextInt();
            a2[i]=sc.nextInt();
            Arrays.fill(count,0);
            int x=Math.min(a1[i],a2[i]);
            p=Math.max(a1[i],a2[i]);
            rec(x);
            if(res==-1)
            {
                System.out.print("-1");
                break;
            }
        }
        if(res!=-1)
            System.out.print(Collections.max(b));
        //System.out.print(b);
        sc.close();
    }
}
