#include #include int cmp(const void *p,const void *q){return *(int*)p-*(int*)q;} int solve(int *d,int m,int cur,int a,int (*f)(int)) { if (cur==m) return f(a); int g(int n){ int p=d[cur*2+1]; return f(n==p?p+1:n==p+1?p:n); } return solve(d,m,cur+1,a,g); } int main() { int m,n,a,i,d[2000]; while(scanf("%d%d%d",&n,&m,&a),m!=0){ int id(int n){ return n; } for (i=0;i