UVALive - 7456
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
#define maxn 105
#define inf 0x3f3f3f3f
vector<int>g[maxn];
int n,sink,m,u,v,ans,ind,sum;
bool vis[maxn];
void dfs(int x,int cur)
{
vis[x]=1;
for(int j=0; j<g[x].size(); j++)
if(!vis[g[x][j]]&&g[x][j]!=cur)
{
sum++;
dfs(g[x][j],cur);
}
}
int main()
{
while(cin>>n)
{
for(int i=1;i<=n;i++)
g[i].clear();
if(!n)
break;
ans=inf;
cin>>sink>>m;
while(m--)
{
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i=1; i<=n; i++)
if(i!=sink)
{
sum=0;
memset(vis,0,sizeof(vis));
dfs(sink,i);
if((sum)<ans)
{
ans=sum;
ind=i;
}
}
cout<<ind<<endl;
}
return 0;
}