二分图匹配,一边是属性值,一边是武器
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, lst[1010005], uu, vv, hea[10005], cnt, ans;
bool vis[1010005];
struct Edge{
int too, nxt;
}edge[2000005];
void add_edge(int fro, int too){
edge[++cnt].nxt = hea[fro];
edge[cnt].too = too;
hea[fro] = cnt;
}
bool dfs(int x){
for(int i=hea[x]; i; i=edge[i].nxt){
int t=edge[i].too;
if(!vis[t]){
vis[t] = true;
if(!lst[t] || dfs(lst[t])){
lst[t] = x;
return true;
}
}
}
return false;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%d %d", &uu, &vv);
add_edge(uu, i+10000);
add_edge(vv, i+10000);
}
for(int i=1; i<=10000; i++){
memset(vis, 0, sizeof(vis));
if(!dfs(i))
break;
ans = i;
}
cout<<ans<<endl;
return 0;
}