1 #include<cstdio>
2 #include<cctype>
3 #include<algorithm>
4 inline int getint() {
5 register char ch;
6 while(!isdigit(ch=getchar()));
7 register int x=ch^'0';
8 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
9 return x;
10 }
11 const int M=10001;
12 int anc[M];
13 bool vis[M];
14 int find(const int &x) {
15 return x==anc[x]?x:anc[x]=find(anc[x]);
16 }
17 int main() {
18 for(register int i=0;i<M;i++) anc[i]=i;
19 for(register int n=getint();n;n--) {
20 int x=find(getint()-1),y=find(getint()-1);
21 if(x==y) {
22 vis[x]=true;
23 } else {
24 if(x>y) std::swap(x,y);
25 vis[vis[x]?y:x]=true;
26 anc[x]=y;
27 }
28 }
29 for(register int i=0;i<M;i++) {
30 if(!vis[i]) {
31 printf("%d\n",i);
32 return 0;
33 }
34 }
35 }