/*
 * Created by SharpDevelop.
 * User: Watson
 * Date: 2017/04/28
 * Time: 21:17
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

namespace NU
{
	class Program
	{
		static Func<int> Read=()=>int.Parse(Console.ReadLine());
		static Func<string[]> Readss=()=>Console.ReadLine().Split(' ');
		static string[] ss=new string[0];
		static Func<int,int> par = i=>int.Parse(ss[i]);
		static int Res=0;
		public static void Main(string[] args)
		{
			int N=Read();
			int[] Tape=new int[100002];
			for(int i=0;i<100002;i++)Tape[i]=0;
			int a,b;
			for(int i=0;i<N;i++){
				ss=Readss();
				a=par(0);b=par(1);
				Tape[a]++;Tape[b]--;
			}
			for(int i=0;i<100001;i++){
				Tape[i+1]+=Tape[i];
				if(i<=Tape[i+1])Res=i;
			}
			Console.WriteLine(Res);
		}
	}
}