#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
struct EXAM
{
int b,a;
}exam[5500];
bool cmp(EXAM x,EXAM y)
{
if(x.a!=y.a)return x.a<y.a;
return x.b<y.b;
}
int n;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&exam[i].a,&exam[i].b);
}
sort(exam,exam+n,cmp);
int day=0;
for(int i=0;i<n;i++)
{
if(day<=exam[i].b&&exam[i].b<exam[i].a)
{
day=exam[i].b;
}
else
{
day=exam[i].a;
}
}
printf("%d\n",day);
return 0;
}