#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 1400);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(1) {

		if(!p[id].y) go(id);

		if(p[id].x>=x) end(p[id].x);

		if(p[id].y==-1) end(-1);

		id=p[id].y;

	}

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(p[id].x>=x) end(p[id].x);

	else end(-1);

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y && id>=1 && id<=n) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(~p[id].y) end(p[id].x);

	else end(-1);

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	srand(time(0));

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 1028);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(~p[id].y) end(p[id].x);

	else end(-1);

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f3f

#define mod 10000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a<b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a>b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a*a%m) if (!b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 111111

int id[NN];

pii p[NN];

void ask(int u){

	putchar('?');

	cout<<' ';

	println(u);

	fflush(stdout);

	gn(p[u].x, p[u].y);

}

void answer(int u){

	putchar('!');

	cout<<' ';

	print(u);

	exit(0);

}

int main() {

	int n, st, x;

	gn(n, st, x);

	srand(time(0));

	for(int i=1; i<=n; i++)	id[i]=i;

	random_shuffle(id+1, id+n+1);

	int N=min(n, 1000);

	ask(st);

	if(p[st].x>=x) answer(p[st].x);

	for(int i=1; i<=N; i++){

		ask(id[i]);

		int u=p[id[i]].x;

		if(u<x and u>p[st].x)	st=id[i];

	}

	for(int i=1; i<1000; i++){

			ask(st);

		if(p[st].x>=x) answer(p[st].x);

		if(p[st].x==-1) answer(-1);

		st=p[st].y;

	}

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 1111

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	int ed=min(1000, (n+1)/2);

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1 && v<xx) return puts("! -1");

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1) return puts("! -1");

		q=nxt;

	}

	if(n>4000) assert(0);

	else {

		while(1) ;

	}

	return puts("! -1");

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2, x3), gn(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {gn(x1, x2, x3, x4), gn(x5);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void print(T1 x1, T2 x2, T3 x3, T4 x4, T5 x5) {printsp(x1), printsp(x2), printsp(x3), printsp(x4), println(x5);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1000100

int a[NN];

pii pa[NN];

int main(){

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

#endif

	srand(time(NULL));

	int n,src,x;

	gn(n,src,x);

	int nn=0;

	for(int i=1;i<=1000;i++){

		int xx=rand()%n+1;

		printf("%c %d\n",'?',xx);

		fflush(stdout);

		int y;

		gn(pa[++nn].x,y);

		pa[nn].y=xx;

	}

	sort(pa+1,pa+nn+1);

	for(int i=1;i<=nn;i++) a[i]=pa[i].x;

	if(a[1]<=x){

		int pos=upper_bound(a+1,a+nn+1,x)-a;

		pos--;

		src=pa[pos].y;

	}

	int D=999;

	while(D--){

		printf("%c %d\n",'?',src);

		fflush(stdout);

		int val,pos;

		gn(val,pos);

		if(val>=x){

			printf("%c %d\n",'!',val);

			fflush(stdout);

			return 0;

		}

		if(pos==-1) break;

		src=pos;

	}

	puts("! -1");

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f3f

#define mod 10000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a<b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a>b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a*a%m) if (!b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 50001

int id[NN];

pii p[NN];

void ask(int u){

	printf("? %d\n", u);

	fflush(stdout);

	gn(p[u].x, p[u].y);

}

void answer(int u){

printf("! %d\n", u);	exit(0);

}

int main() {

	int n, st, x;

	gn(n, st, x);

	srand(time(0));

	for(int i=1; i<=n; i++)	id[i]=i;

	random_shuffle(id+1, id+n+1);

	int N=min(n, 1000);

	ask(st);

	if(p[st].x>=x) answer(p[st].x);

	for(int i=1; i<=N; i++){

		ask(id[i]);

		int u=p[id[i]].x;

		if(u<x and u>p[st].x)	st=id[i];

	}

	for(int i=1; i<1000; i++){

		ask(st);

		if(p[st].x>=x) answer(p[st].x);

		if(p[st].x==-1) answer(-1);

		st=p[st].y;

	}

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 1111

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	int ed=min(1400, (n+1)/2);

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v), 0;

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 2222

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	srand(time(NULL));

	int mx=0, ed=0;

	for(int i=1; i<=n; i+=50) {

		int u=rand()%50+i;

		if(ed==0) u=s;

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		smax(mx, v);

		if(ed==1 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		info[ed].x=v;

		info[ed].y=nxt;

		ed++;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	if(n>40000) assert(0);

	else {

		while(1) ;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 55555

bool vst[NN];

int main(){

	srand(time(NULL));

	int N, X, st, p, val;

	cin>>N>>st>>X;

	printf("? %d\n", st);

	fflush(stdout);

	scanf("%d%d", &val, &p);

	if (X<val) {

		puts("! -1");

		fflush(stdout);

		return 0;

	}

	vst[st]=1;

	int mm=val, pos=st;

	int step=75577, n=st;

	for (int i=0; i<1000 && i<N; i++) {

		int n=(n+step)%N;

		if(n==0) n=N;

		printf("? %d\n", n);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>X) continue;

		if (val==X) {

			printf("! %d\n", X);

			fflush(stdout);

			return 0;

		}

		if (X-val<X-mm) {

			mm=val;

			pos=n;

		}

	}

	st=pos;

	for (int i=0; i<990 && i<N; i++) {

		printf("? %d\n", st);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X) {

			printf("! %d\n", val);

			fflush(stdout);

			return 0;

		}

		if (p<0) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		st=p;

	}

	puts("! -1");

	fflush(stdout);

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 1111

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	for(int i=0; i<min(n/2, 1000); i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag[u]) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1 && v<xx) return puts("! -1");

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+1000);

	int pos;

	for(int i=0; i<1000; i++) {

		if(info[i].x>xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1000; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1) return puts("! -1");

		q=nxt;

	}

	return puts("! -1");

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void getint(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#ifndef ONLINE_JUDGE

void debug() {cout << endl;}

template<typename T, typename... Args>void debug(T&& head, Args&&... tail) {cout << head << ' ';debug(tail...);}

#endif

#define NN 55555

int nxt[NN], val[NN], id[NN];

void query(int x){

	printf("? %d\n", x);

	fflush(stdout);

	scanf("%d %d", val+x, nxt+x);

}

void print(int ans){

	printf("! %d\n", ans);

	fflush(stdout);

	exit(0);

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, st, x;

	cin >> n >> st >> x;

	if(n<2000){

		int ans=inf;

		for(int i=1; i<=n; i++){

			query(i);

			if(val[i]>=x && val[i]<ans) ans=val[i];

		}

		if(ans==inf) print(-1);

		else print(ans);

	}

	query(st);

	if(val[st]>=x) print(val[st]);

	for(int i=1; i<=n; i++) id[i]=i;

	random_shuffle(id+1, id+n+1);

	int cur=st;

	for(int i=1, k=0; i<=n && k<1200; i++){

		k++;

		query(id[i]);

		if(val[id[i]]<x && val[id[i]]>val[cur]) cur=id[i];

	}

	int k=800;

	cur=nxt[cur];

	if(cur==-1) print(-1);

	while(--k){

		query(cur);

		if(val[cur]>=x) print(val[cur]);

		if(nxt[cur]==-1) print(-1);

		cur=nxt[cur];

	}

	print(x);

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2, x3), gn(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {gn(x1, x2, x3, x4), gn(x5);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

template <class T1, class T2, class T3, class T4, class T5> inline void print(T1 x1, T2 x2, T3 x3, T4 x4, T5 x5) {printsp(x1), printsp(x2), printsp(x3), printsp(x4), println(x5);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 1000100

int a[NN];

pii pa[NN];

int main(){

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

#endif

	srand(time(NULL));

	int n,src,x;

	gn(n,src,x);

	int nn=0;

	for(int i=1;i<=1000;i++){

		int xx=(INT)(rand()%20000+1)*(rand()%20000+1)%n+1;

		printf("%c %d\n",'?',xx);

		fflush(stdout);

		int y;

		gn(pa[++nn].x,y);

		pa[nn].y=xx;

	}

	sort(pa+1,pa+nn+1);

	for(int i=1;i<=nn;i++) a[i]=pa[i].x;

	if(a[1]<=x){

		int pos=upper_bound(a+1,a+nn+1,x)-a;

		pos--;

		src=pa[pos].y;

	}

	int D=999;

	while(D--){

		printf("%c %d\n",'?',src);

		fflush(stdout);

		int val,pos;

		gn(val,pos);

		if(val>=x){

			printf("%c %d\n",'!',val);

			fflush(stdout);

			return 0;

		}

		if(pos==-1) break;

		src=pos;

	}

	puts("-1");

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 100010

int id[NN];

int main() {

	int N, st, X, val, p, ID, V;

	cin>>N>>st>>X;

	for (int i=1; i<=N; i++) id[i]=i;

	random_shuffle(id+1, id+N+1);

	printf("? %d\n", st);fflush(stdout);

	scanf("%d%d", &val, &p);

	if(val>X){

		puts("! -1");

		return 0;

	}

	V=val, ID=st;

	for (int i=1; i<=1400 && i<N; i++) {

		printf("? %d\n", id[i]);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val==X) {

			printf("! %d\n", X);fflush(stdout);

			return 0;

		}

		if (val<X) {

			if (X-val<X-V) {

				V=val;

				ID=id[i];

			}

		}

	}

	for (int i=0; i<599 && i<N; i++) {

		printf("? %d\n", ID);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X){

			printf("! %d\n", val);fflush(stdout);

			return 0;

		}

		ID=p;

		if (ID<0) {

			puts("! -1");fflush(stdout);

			return 0;

		}

	}

	puts("! -1");fflush(stdout);

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y && id>=1 && id<=n) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(id>=1 && id<=n && p[id].x>=x) end(p[id].x);

	else end(-1);

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 100010

int id[NN];

int main() {

	int N, st, X, val, p, ID, V;

	cin>>N>>st>>X;

	for (int i=1; i<=N; i++) id[i]=i;

	srand(time(NULL));

	random_shuffle(id+1, id+N+1);

	printf("? %d\n", st);fflush(stdout);

	scanf("%d%d", &val, &p);

	V=val, ID=st;

	for (int i=1; i<=1400 && i<N; i++) {

		printf("? %d\n", id[i]);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val==X) {

			printf("! %d\n", X);fflush(stdout);

			return 0;

		}

		if (val<X) {

			if (X-val<X-V) {

				V=val;

				ID=id[i];

			}

		}

	}

	for (int i=0; i<599 && i<N; i++) {

		printf("? %d\n", ID);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X){

			printf("! %d\n", val);fflush(stdout);

			return 0;

		}

		ID=p;

		if (ID<0) {

			puts("! -1");fflush(stdout);

			return 0;

		}

	}

	puts("! -1");fflush(stdout);

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	srand(time(0));

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 1400);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(1) {

		if(!p[id].y) go(id);

		if(p[id].x>=x) end(p[id].x);

		if(p[id].y==-1) end(-1);

		id=p[id].y;

	}

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 55555

pii p[NN];

int f[NN];

void ask(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void answer(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	srand(time(0));

	random_shuffle(f+1, f+n+1);

	ask(id);

	if(p[id].x>=x) answer(p[id].x);

	int N=min(n, 1000);

	for(int i=1; i<=N; i++) {

		ask(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	for(int i=0; i<1000; i++){

		if(!p[id].y) ask(id);

		if(p[id].x>=x) answer(p[id].x);

		if(p[id].y==-1) answer(-1);

		id=p[id].y;

	}

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 120);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(p[id].x>=x) end(p[id].x);

	else end(-1);

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 55555

bool vst[NN];

int main(){

	srand(time(NULL));

	int N, X, st, p, val;

	cin>>N>>st>>X;

	printf("? %d\n", st);

	fflush(stdout);

	scanf("%d%d", &val, &p);

	if (X<val) {

		puts("! -1");

		return 0;

	}

	vst[st]=1;

	int mm=val, pos=st;

	for (int i=0; i<1000; i++) {

		rand();

		rand();

		rand();

		int n=rand()%N+1, nn=0;

		while (nn<N && vst[n]) n=rand()%N+1, nn++;

		if (vst[n]) continue;

		vst[n]=1;

		printf("? %d\n", n);fflush(stdout);

		scanf("%d%d", &val, &p);

		vst[p]=1;

		if (val>X) continue;

		if (val==X) {

			printf("! %d\n", X);

			return 0;

		}

		if (X-val<X-mm) {

			mm=val;

			pos=n;

		}

	}

	st=pos;

	for (int i=0; i<990; i++) {

		printf("? %d\n", st);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X) {

			printf("! %d\n", val);

			return 0;

		}

		if (p<0) {

			puts("! -1");

			return 0;

		}

		st=p;

	}

	puts("! -1");

	while(true);

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 55555

bool vst[NN];

int main(){

	srand(time(NULL));

	int N, X, st, p, val;

	cin>>N>>st>>X;

	printf("? %d\n", st);

	fflush(stdout);

	scanf("%d%d", &val, &p);

	if (X<val) {

		puts("! -1");

		fflush(stdout);

		return 0;

	}

	vst[st]=1;

	int mm=val, pos=st;

	for (int i=0; i<1000; i++) {

		rand();rand();rand();rand();

		int n=rand()%N+1, nn=0;

		while (nn<N && vst[n]) n=rand()%N+1, nn++;

		if (vst[n]) continue;

		vst[n]=1;

		printf("? %d\n", n);fflush(stdout);

		scanf("%d%d", &val, &p);

		vst[p]=1;

		if (val>X) continue;

		if (val==X) {

			printf("! %d\n", X);

			fflush(stdout);

			return 0;

		}

		if (X-val<X-mm) {

			mm=val;

			pos=n;

		}

	}

	st=pos;

	for (int i=0; i<990; i++) {

		printf("? %d\n", st);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X) {

			printf("! %d\n", val);

			fflush(stdout);

			return 0;

		}

		if (p<0) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		st=p;

	}

	puts("! -1");

	fflush(stdout);

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

using namespace std;

#define NN 100010

int id[NN];

int main() {

	int N, st, X, val, p, ID, V;

	cin>>N>>st>>X;

	for (int i=1; i<=N; i++) id[i]=i;

	random_shuffle(id+1, id+N+1);

	printf("? %d\n", st);fflush(stdout);

	scanf("%d%d", &val, &p);

	V=val, ID=st;

	for (int i=1; i<=1400 && i<N; i++) {

		printf("? %d\n", id[i]);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val==X) {

			printf("! %d\n", X);fflush(stdout);

			return 0;

		}

		if (val<X) {

			if (X-val<X-V) {

				V=val;

				ID=id[i];

			}

		}

	}

	for (int i=0; i<599 && i<N; i++) {

		printf("? %d\n", ID);fflush(stdout);

		scanf("%d%d", &val, &p);

		if (val>=X){

			printf("! %d\n", val);fflush(stdout);

			return 0;

		}

		ID=p;

		if (ID<0) {

			puts("! -1");fflush(stdout);

			return 0;

		}

	}

	puts("! -1");fflush(stdout);

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(1) {

		if(!p[id].y) go(id);

		if(p[id].x>=x) end(p[id].x);

		if(p[id].y==-1) end(-1);

		id=p[id].y;

	}

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	srand(time(0));

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(1) {

		if(!p[id].y) go(id);

		if(p[id].x>=x) end(p[id].x);

		if(p[id].y==-1) end(-1);

		id=p[id].y;

	}

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 2222

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	srand(time(NULL));

	int ed=min(500, (n+1)/2);

	int mx=0;

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		smax(mx, v);

		if(i==0 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	if(mx<xx) {

		for(int i=ed; i<min(ed+500, n); i++) {

			int u=rand()%n+1;

			while(flag.count(u)) {

				u=rand()%n+1;

			}

			printf("? %d\n", u);

			fflush(stdout);

			int v, nxt;

			scanf("%d %d", &v, &nxt);

			smax(mx, v);

			if(nxt==-1 && v<xx) {

				puts("! -1");

				fflush(stdout);

				return 0;

			}

			flag[u]=flag[nxt]=1;

			info[i].x=v;

			info[i].y=nxt;

		}

		ed=min(ed+500, n);

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	if(n>50000) assert(0);

	else {

		while(1) ;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 2222

map<int, int> flag;

pii info[NN];

int id[50010];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	srand(time(NULL));

	int ed=min(1200, (n+1)/2);

	for(int i=0; i<n; i++) id[i]=i+1;

	random_shuffle(id, id+n);

	for(int i=0; i<ed; i++) {

		int u=id[i];

		if(i==0) u=s;

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v), 0;

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 2222

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	int ed=min(1400, (n+1)/2);

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		flag[u]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v), 0;

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f3f

#define mod 10000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a<b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a>b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a*a%m) if (!b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 55555

int id[NN];

pii p[NN];

void ask(int u){

	printf("? %d\n", u);

	fflush(stdout);

	gn(p[u].x, p[u].y);

}

void answer(int u){

	printf("! %d\n", u);	exit(0);

}

int main() {

	int n, st, x;

	gn(n, st, x);

	srand(time(0));

	for(int i=1; i<=n; i++)	id[i]=i;

	random_shuffle(id+1, id+n+1);

	int N=min(n, 1000);

	ask(st);

	if(p[st].x>=x) answer(p[st].x);

	for(int i=1; i<=N; i++){

		ask(id[i]);

		int u=p[id[i]].x;

		if(u<x and u>p[st].x)	st=id[i];

	}

	for(int i=1; i<1000; i++){

		ask(st);

		if(p[st].x>=x) answer(p[st].x);

		if(p[st].x==-1) answer(-1);

		st=p[st].y;

	}

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 1000);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(p[id].x>=x) end(p[id].x);

	else end(-1);

}


#include <bits/stdc++.h>

#define x first

#define y second

#define eps 1e-8

#define pb push_back

#define mod 1000000007

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=(INT)a*a%m) if (b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 50010

pii p[NN];

int f[NN];

void go(int x) {

	printf("? %d\n", x);

	fflush(stdout);

	gn(p[x].x, p[x].y);

}

void end(int x) {

	printf("! %d\n", x);

	exit(0);

}

int main() {

	int n, id, x;

	gn(n, id, x);

	for(int i=1; i<=n; i++) f[i]=i;

	srand(time(0));

	random_shuffle(f+1, f+n+1);

	go(id);

	if(p[id].x>=x) end(p[id].x);

	int N=min(n, 728);

	for(int i=1; i<=N; i++) {

		go(f[i]);

		int u=p[f[i]].x;

		if(u<x && u>p[id].x) id=f[i];

	}

	while(p[id].x<x && ~p[id].y) {

		id=p[id].y;

		if(!p[id].y) go(id);

	}

	if(~p[id].y) end(p[id].x);

	else end(-1);

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 1111

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	int ed=min(1000, (n+1)/2);

	int mx=0;

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		smax(mx, v);

		if(i==0 && v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1 && v<xx) return puts("! -1");

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	if(mx<xx) {

		for(int i=ed; i<min(ed+500, n); i++) {

			int u=rand()%n+1;

			while(flag.count(u)) {

				u=rand()%n+1;

			}

			printf("? %d\n", u);

			fflush(stdout);

			int v, nxt;

			scanf("%d %d", &v, &nxt);

			smax(mx, v);

			if(nxt==-1 && v<xx) return puts("! -1");

			flag[u]=flag[nxt]=1;

			info[i].x=v;

			info[i].y=nxt;

		}

		ed=min(ed+500, n);

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) return printf("! %d\n", v), 0;

		if(nxt==-1) return puts("! -1");

		q=nxt;

	}

	if(n>10000) assert(0);

	else {

		while(1) ;

	}

	return puts("! -1");

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#define ONLINE_JUDGE
#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

#define NN 2222

map<int, int> flag;

pii info[NN];

int main() {

#ifndef ONLINE_JUDGE

//	freopen("in.in", "r", stdin);

//	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n, s, xx;

	cin>>n>>s>>xx;

	int nn=0;

	int ed=min(1400, (n+1)/2);

	for(int i=0; i<ed; i++) {

		int u=rand()%n+1;

		if(i==0) u=s;

		while(flag.count(u)) {

			u=rand()%n+1;

		}

		printf("? %d\n", u);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(i==0 && v>=xx) {

			printf("! %d\n", v);

			fflush(stdout);

			return 0;

		}

		if(nxt==-1 && v<xx) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		flag[u]=flag[nxt]=1;

		info[i].x=v;

		info[i].y=nxt;

	}

	sort(info, info+ed);

	int pos;

	for(int i=0; i<ed; i++) {

		if(info[i].x>=xx) break;

		pos=i;

	}

	int q=info[pos].y;

	for(int i=0; i<1999-ed; i++) {

		printf("? %d\n", q);

		fflush(stdout);

		int v, nxt;

		scanf("%d %d", &v, &nxt);

		if(v>=xx) {

			printf("! %d\n", v), 0;

			fflush(stdout);

			return 0;

		}

		if(nxt==-1) {

			puts("! -1");

			fflush(stdout);

			return 0;

		}

		q=nxt;

	}

	puts("! -1");

	fflush(stdout);

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int k[100001],b[100001],id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (k[j]==0) return true;
     if (b[i]/k[i]<b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%d %d",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    if (k[id[0]]!=0) ans++;
    long long q = 0,t = 0;
    for (int i=1;i<n;i++) {
        if (k[id[i]]==0) break;
        t += k[id[i]];
        if (i<n-1 && k[id[i]]*b[id[i+1]]==k[id[i+1]]*b[id[i]])
           continue;
        if (t!=q) ans++;
        q = t;
    }
    cout <<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int k[100001],b[100001],id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (k[j]==0) return true;
     if (b[i]/k[i]<b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%d%d",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    if (k[id[0]]!=0) ans++;
    for (int i=1;i<n;i++) {
        if (k[id[i]]==0) break;
        if (k[id[i]]*b[id[i-1]]==k[id[i-1]]*b[id[i]]) continue;
        ans++;
    }
    cout <<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
double k[100001],b[100001];
int id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (k[j]==0) return true;
     if (b[i]/k[i]<b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%lf%lf",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    if (k[id[0]]!=0) ans++;
    for (int i=1;i<n;i++) {
        if (k[id[i]]==0) break;
        if (k[id[i]]*b[id[i-1]]==k[id[i-1]]*b[id[i]]) continue;
        ans++;
    }
    cout <<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int k[100001],b[100001],id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (b[i]/k[i]<b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%d%d",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    if (k[id[0]]!=0) ans++;
    for (int i=1;i<n;i++) {
        if (k[id[i]]==0) break;
        if (k[id[i]]*b[id[i-1]]==k[id[i-1]]*b[id[i]]) continue;
        ans++;
    }
    cout <<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int k[100001],b[100001],id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (k[j]==0) return true;
     if (b[i]/k[i]>b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%d %d",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    long long q = 0,t = 0;
    for (int i=0;i<n;i++)
        if (k[id[i]]<0) q+=k[id[i]];
    t = q;
    for (int i=0;i<n;i++) {
        if (k[id[i]]==0) break;
        if (k[id[i]]<0) t -= k[id[i]]; else t+=k[id[i]];
        if (i<n-1 && k[id[i]]*b[id[i+1]]==k[id[i+1]]*b[id[i]])
           continue;
        if (t!=q) ans++;
        q = t;
    }
    cout <<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int k[100001],b[100001],id[100001];
bool cmp(int i,int j) {
     if (k[i]==0) return false;
     if (k[j]==0) return true;
     if (b[i]/k[i]>b[j]/k[j]) return true;
     return false;
}
int main() {
    int n;
    cin >>n;
    for (int i=0;i<n;i++) {
        scanf("%d %d",&k[i],&b[i]);
        id[i] = i;
    }
    sort(id,id+n,cmp);
    int ans=0;
    if (k[id[0]]!=0) ans++;

    for (int i=1;i<n;i++) {
        if (k[id[i]]==0) break;
        if (b[id[i]]/k[id[i]]==b[id[i-1]]/k[id[i-1]])
           continue;
        ans++;
    }
    cout <<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-6;

int n;
double k[N], b[N];

struct Data {
    int id;
    bool tp;
    double t;
    Data(int _id = 0, int _tp = 0, int _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];

inline bool zero(double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        scanf("%lf%lf", k+i, b+i);
        if(k[i]) g[i] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] <= 0) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+n+1);
    for(int i = 1; i <= n; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        if(zero(tk-sk) && zero(tb-sb))
            continue;
        else ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-10;

int n;
long double k[N], b[N];

struct Data {
    int id;
    bool tp;
    long double t;
    Data(int _id = 0, bool _tp = 0, long double _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];
int tot;

inline bool zero(double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    long double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        double p, q;
        scanf("%lf%lf", &p, &q);
        k[i] = p, b[i] = q;
        if(k[i]) g[++tot] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] < 0 || (k[i] == 0 && b[i] > 0)) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+tot+1);
    for(int i = 1; i <= tot; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-15;

int n;
long double k[N], b[N];

struct Data {
    int id;
    bool tp;
    long double t;
    Data(int _id = 0, bool _tp = 0, long double _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];
int tot;

inline bool zero(long double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    long double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        double p, q;
        scanf("%lf%lf", &p, &q);
        k[i] = p, b[i] = q;
        if(k[i]) g[++tot] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] < 0 || (k[i] == 0 && b[i] > 0)) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+tot+1);
    for(int i = 1; i <= tot; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-6;

int n;
long double k[N], b[N];

struct Data {
    int id;
    bool tp;
    long double t;
    Data(int _id = 0, bool _tp = 0, long double _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];
int tot;

inline bool zero(double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    long double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        double p, q;
        scanf("%lf%lf", &p, &q);
        k[i] = p, b[i] = q;
        if(k[i]) g[++tot] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] < 0 || (k[i] == 0 && b[i] > 0)) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+tot+1);
    for(int i = 1; i <= tot; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-6;

int n;
long double k[N], b[N];

struct Data {
    int id;
    bool tp;
    long double t;
    Data(int _id = 0, bool _tp = 0, long double _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];

inline bool zero(double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    long double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        double p, q;
        scanf("%lf%lf", &p, &q);
        k[i] = p, b[i] = q;
        if(k[i]) g[i] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] < 0 || (k[i] == 0 && b[i] > 0)) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+n+1);
    for(int i = 1; i <= n; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;

int n;

struct Data {
    int id;
    bool tp;
    long long k, b;
    Data(int _id = 0, bool _tp = 0, long long _k = 0, long long _b = 0) {id = _id, tp = _tp, k = _k, b = _b;}
    inline friend bool operator < (const Data &p, const Data &q) {
        if(p.k*q.k > 0) return -p.b*q.k < -q.b*p.k;
        else return -p.b*q.k > -q.b*p.k;
    }
}g[N];
int tot;

int main() {
    scanf("%d", &n);
    long long tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        int k, b;scanf("%d%d", &k, &b);
        if(k) g[++tot] = Data(i, k>0, k, b);
        if(k < 0 || (k == 0 && b > 0)) tk += k, tb += b;
    }
    int ans = 0;
    sort(g+1, g+tot+1);
    for(int i = 1; i <= tot; ++i) {
        int j = i;
        long long sk = tk, sb = tb;
        tk -= g[i].k, tb -= g[i].b;
        while(j < tot && g[j+1].k*g[j].b == g[j].k*g[j+1].b) {
            ++j;
            if(g[j].tp) tk += g[j].k, tb += g[j].b;
            else tk -= g[j].k, tb -= g[j].b;
        }
        if(tk == sk && tb == sb) continue;
        else ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100009;
const double eps = 1e-6;

int n;
long double k[N], b[N];

struct Data {
    int id;
    bool tp;
    long double t;
    Data(int _id = 0, bool _tp = 0, long double _t = 0) {id = _id, tp = _tp, t = _t;}
    inline friend bool operator < (const Data &p, const Data &q) {
        return p.t < q.t;
    }
}g[N];

inline bool zero(double k) {
    return fabs(k) <= eps;
}

int main() {
    scanf("%d", &n);
    long double tk = 0, tb = 0;
    for(int i = 1; i <= n; ++i) {
        double p, q;
        scanf("%lf%lf", &p, &q);
        k[i] = p, b[i] = q;
        if(k[i]) g[i] = Data(i, k[i]>0, -b[i]/k[i]);
        if(k[i] < 0 || (k[i] == 0 && b[i] > 0)) tk += k[i], tb += b[i];
    }
    int ans = 0;
    sort(g+1, g+n+1);
    for(int i = 1; i <= n; ++i) {
        int j = i;
        double sk = tk, sb = tb;
        tk -= k[g[i].id], tb -= b[g[i].id];
        while(j < n && zero(g[j+1].t-g[j].t)) {
            ++j;
            tk -= k[g[j].id], tb -= b[g[j].id];
        }
        if(zero(tk-sk) && zero(tb-sb))
            continue;
        else ans++;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  int k , b;
  double x;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  return x.x < y.x;
}
int main()
{

  cin >> n;
  int i , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k)
    {
      i -- , n --;
      continue;
    }
    if (l[i].k < 0)
       lk += l[i].k;
    l[i].x = double(-l[i].b) / l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;
    if (l[i].x == l[i - 1].x && i != 1)
      ans --;
    else if (k[i] == k[i - 1])
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  int k , b;
  double x;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  return x.x < y.x;
}
int main()
{
  //freopen("~input.txt","r",stdin);
  //freopen("~output.txt","w",stdout);
  cin >> n;
  int i , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k)
    {
      i -- , n --;
      continue;
    }
    if (l[i].k < 0)
       lk += l[i].k;
    l[i].x = double(-l[i].b) / l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;
    if (k[i] == k[i - 1])
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  long long k , b;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  if (x.k * y.k > 0)
    return x.b * y.k - x.k * y.b > 0;
  return x.b * y.k - x.k * y.b < 0;
}
int main()
{
  cin >> n;
  int i , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k)
    {
      i -- , n --;
      continue;
    }
    if (l[i].k < 0)
       lk += l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;
    if (i != 1 && l[i].k * l[i - 1].b == l[i - 1].k * l[i].b )
      ans --;
    else if (k[i] == k[i - 1])
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  int k , b;
  double x;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  return x.x < y.x;
}
int main()
{
  cin >> n;
  int i , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k)
    {
      i -- , n --;
      continue;
    }
    if (l[i].k < 0)
       lk += l[i].k;
    l[i].x = double(-l[i].b) / l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;
    if (k[i] == k[i - 1])
      ans --;
    else if (l[i].x == l[i - 1].x && i != 1)
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  int k , b;
  double x;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  return x.x < y.x;
}
int main()
{
  cin >> n;
  int i , x , y , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k) i -- , n --;
    if (l[i].k < 0)
       lk += l[i].k;
    l[i].x = double(-l[i].b) / l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;

    if (k[i] == k[i - 1])
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 25005
using namespace std;
int n;
int main()
{
  cin >> n;
  int i , x , y , ans = n;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> x >> y;
    if (!x) ans --;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;
int n ;
long long lk , rk;
struct line
{
  int k , b;
  double x;
}l[N];
long long k[N];
bool cmp(line x , line y)
{
  if (x.x == y.x)
  {
    return x.k > y.k;
  }
  return x.x < y.x;
}
int main()
{
  cin >> n;
  int i , ans;
  for (i = 1 ;i <= n ;i ++)
  {
    cin >> l[i].k >> l[i].b;
    if (!l[i].k)
    {
      i -- , n --;
      continue;
    }
    if (l[i].k < 0)
       lk += l[i].k;
    l[i].x = double(-l[i].b) / l[i].k;
  }
  sort(l + 1 , l + 1 + n , cmp);
  k[0] = lk;
  ans = n;
  for (i = 1 ; i <= n ;i ++)
  {
    if (l[i].k > 0)
      rk += l[i].k;
    if (l[i].k < 0)
      lk -= l[i].k;
    k[i] = lk + rk;
    if (k[i] == k[i - 1])
      ans --;
    else if (l[i].x == l[i - 1].x && i != 1)
      ans --;
  }
  cout << ans << endl;
  return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.0000000000001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.0001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.0000000000000000001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.0000000000000001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
long double a[100005];
int main()
{
       cin>>n;
       int i,m=0,ans;
       double b,k;
       for (i=1;i<=n;i++)
       {
              cin>>k>>b;
              if (k!=0) a[++m]=-(b/k);
       }
       sort(a+1,a+1+m);

       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>1e-50) ans++;
       if (m) ans++;
       cout<<ans<<endl;
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.000000001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>1e-50) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>0.0001) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#define oo 2000000000
#define ll long long
using namespace std;
int n;
double a[100005];
int main()
{
       scanf("%d",&n);
       int i,b,k,m=0,ans;
       for (i=1;i<=n;i++)
       {
              scanf("%d%d",&k,&b);
              if (k!=0) a[++m]=-b/(double)k;
       }
       sort(a+1,a+1+m);
       ans=0;
       for (i=2;i<=m;i++)
          if (fabs(a[i]-a[i-1])>1e-30) ans++;
       if (m) ans++;
       printf("%d\n",ans);
       return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int n;
long double a[100005];
double fabs(double a)
{
    if(a<0)
    return -a;
}
int main()
{
    int i,m=0,ans;
    double b,k;
     while(~scanf("%d",&n))
     {
         m=0;
         for(i=1;i<=n;i++)
    {
        cin>>k>>b;
        if(k!=0) a[++m]=-(b/k);
    }
    sort(a+1,a+1+m);
    ans=0;
    for (i=2;i<=m;i++)
    {
        if(fabs(a[i]-a[i-1]>1e-20)) ans++;
    }
    if (m) ans++;
    cout<<ans<<endl;
     }
    return 0;
}