n=int(input())
s1=input()
s2=input()
first=[]
second=[]
reserve=[]
waste=[]
ans=[]
lf=0
ls=0
for i in range(n):
    if s1[i]=="1" and s2[i]=="0":
        second.append(i+1)
        ls+=1
    elif s1[i]=="0" and s2[i]=="1":
        first.append(i+1)
        lf+=1
    elif s1[i]=="1" and s2[i]=="1":
        reserve.append(i+1)

    else:
        waste.append(i+1)

ans1=[]
ans2=[]
if lf<ls:
    for i in range(min(lf,ls)):
        ans1.append(first[i])
        ans2.append(second[i])
    for i in range(len(reserve)):
        try:
            ans1.append(second[i+lf])
            ans2.append(reserve[i])
        except:
            ans1.append(reserve[i])
            ans2.append(ans1.pop(0))
    j=0
    for i in range(lf+len(reserve),ls):
        try:
            ans1.append(second[i])
            ans2.append(waste.pop())
            j+=1
        except:
            break
else:
    for i in range(min(lf,ls)):
        ans1.append(first[i])
        ans2.append(second[i])
    for i in range(len(reserve)):
        try:
            ans2.append(first[i+ls])
            ans1.append(reserve[i])
        except:
            ans2.append(reserve[i])
            ans1.append(ans2.pop(0))
    j=0
    for i in range(ls+len(reserve),lf):
        try:
            ans2.append(first[i])
            ans1.append(waste.pop())
            j+=1
        except:
            break
while waste:
    if len(ans1)<len(ans2):
        ans1.append(waste.pop())
    else:
        ans2.append(waste.pop())

fa=0
sa=0
for i in ans1:
    if s1[i-1]=="1":
        fa+=1
#print(ans1,ans2)
for i in ans2:
    if s2[i-1]=="1":
        sa+=1
if fa==sa and len(ans1)==n//2:
    print(*sorted(ans1))
else:
    print("-1")


n=int(input())
s1=input()
s2=input()
first=[]
second=[]
none=[]
both=[]
for i in range(n):
    if s1[i]=="1" and s2[i]=="0":
        first.append(i+1)
    elif s1[i]=="0" and s2[i]=="1":
        second.append(i+1)
    elif s1[i]=="1" and s2[i]=="1":
        both.append(i+1)
    else:
        none.append(i+1)
fl=len(first)
sl=len(second)
bl=len(both)
nl=len(none)
ans=[]
flag=0
for a in range(fl+1):
    for c in range(bl+1):
        b=(a+c)-(bl-c)
        if b<=sl and b>=0 and a+c+(sl-b)<=(n//2) and b+(bl-c)==a+c:
          #  print(b+(bl-c),a,c)
            ans=[a,sl-b,c,n//2-(a+c+(sl-b))]
            if ans[3]<=nl and ans[3]>=0:
              #  print(ans)
                flag=1
                break
    if flag==1:
        break
if flag==1:
    #print(ans)
    print(*first[:ans[0]],*second[:ans[1]],*both[:ans[2]],*none[:ans[3]])

else:
    print("-1")


import sys
N = int(input())
n = N//2

A = input()
B = input()
C = [(a == '1') * 2 + (b == '1') for a, b in zip(A, B)]

w = C.count(0)
x = C.count(1)
y = C.count(2)
z = N - w - x - y
Ans = []
for i in range(x + 1):
    for j in range(y + 1):
        z1 = (y + z - i - j)
        if z1 % 2:
            continue
        z1 //= 1
        if not 0 <= z1 <= z:
            continue
        w1 = n - i - j - z1
        if not 0 <= w1 <= w:
            continue
        cnt = [w1, j, i, z1]
        ans = []
        for i, a, b in zip(range(1, N+1), A, B):
            if cnt[(a == '1') * 2 + (b == '1')] > 0:
                cnt[(a == '1') * 2 + (b == '1')] -= 1
                Ans.append(i)
        print(*Ans)
        sys.exit()
print(-1)


import sys
N = int(input())
n = N//2

A = input()
B = input()
C = [(a == '1') * 2 + (b == '1') for a, b in zip(A, B)]

w = C.count(0)
x = C.count(1)
y = C.count(2)
z = N - w - x - y
Ans = []
for i in range(x + 1):
    for j in range(y + 1):
        z1 = (y + z - i - j)
        if z1 % 2:
            continue
        z1 //= 2
        if not 0 <= z1 <= z:
            continue
        w1 = n - i - j - z1
        if not 0 <= w1 <= w:
            continue
        cnt = [w1, i, j, z1]
        ans = []
        for i, a, b in zip(range(1, N+1), A, B):
            if cnt[(a == '1') * 2 + (b == '1')] > 0:
                cnt[(a == '1') * 2 + (b == '1')] -= 1
                Ans.append(i)
        print(*Ans)
        sys.exit()
print(-1)


import sys
N = int(input())
n = N//2

A = input()
B = input()
C = [(a == '1') * 2 + (b == '1') for a, b in zip(A, B)]

w = C.count(0)
x = C.count(1)
y = C.count(2)
z = N - w - x - y
Ans = []
for i in range(x + 1):
    for j in range(y + 1):
        z1 = (x + z - i - j)
        if z1 % 2:
            continue
        z1 //= 2
        if not 0 <= z1 <= z:
            continue
        w1 = n - i - j - z1
        if not 0 <= w1 <= w:
            continue
        cnt = [w1, i, j, z1]
        ans = []
        for k, a, b in zip(range(1, N+1), A, B):
            if cnt[(a == '1') * 2 + (b == '1')] > 0:
                cnt[(a == '1') * 2 + (b == '1')] -= 1
                Ans.append(k)
        print(*Ans)
        sys.exit()
print(-1)


n = int(input())
y = list(map(int, list(input())))
a = list(map(int, list(input())))

x = [0, 0, 0, 0]
for i in range(n):
    if y[i] == 0:
        if a[i] == 0:
            x[0] += 1
        else:
            x[1] += 1
    else:
        if a[i] == 0:
            x[2] += 1
        else:
            x[3] += 1

ok = False
ans = []
for c in range(x[2] + 1):
    for d in range(x[3] + 1):
        b = x[1] + x[3] - c - 2 * d
        if 0 <= b + c + d <= n // 2 and 0 <= b <= x[1]:
            ok = True
            ans = [n // 2 - (b + c + d), b, c, d]
if not ok:
    print(-1)
    exit()

fin = []
for i in range(n):
    cur = -1
    if y[i] == 0:
        if a[i] == 0:
            cur = 0
        else:
            cur = 1
    else:
        if a[i] == 0:
            cur = 2
        else:
            cur = 3
    if ans[cur] > 0:
        ans[cur] -= 1
        fin.append(i + 1)
print(*fin)


n = int(input())
y = list(map(int, list(input())))
a = list(map(int, list(input())))

x = [0, 0, 0, 0]
for i in range(n):
    if y[i] == 0:
        if a[i] == 0:
            x[0] += 1
        else:
            x[1] += 1
    else:
        if a[i] == 0:
            x[2] += 1
        else:
            x[3] += 1

ok = False
ans = []
for c in range(x[2] + 1):
    for d in range(x[3] + 1):
        b = x[1] + x[3] - c - 2 * d
        if b + c + d <= n // 2 and 0 <= b <= x[1]:
            ok = 1
            ans = [n // 2 - (b + c + d), b, c, d]
if not ok:
    print(-1)
    exit()

fin = []
for i in range(n):
    cur = -1
    if y[i] == 0:
        if a[i] == 0:
            cur = 0
        else:
            cur = 1
    else:
        if a[i] == 0:
            cur = 2
        else:
            cur = 3
    if ans[cur] > 0:
        ans[cur] -= 1
        fin.append(i + 1)
print(*fin)


n = int(input())
y = list(map(int, list(input())))
a = list(map(int, list(input())))

x = [0, 0, 0, 0]
for i in range(n):
    if y[i] == 0:
        if a[i] == 0:
            x[0] += 1
        else:
            x[1] += 1
    else:
        if a[i] == 0:
            x[2] += 1
        else:
            x[3] += 1

ok = False
ans = []
for c in range(x[2] + 1):
    for d in range(x[3] + 1):
        b = x[1] + x[3] - c - 2 * d
        if 0 <= b + c + d <= n // 2 and 0 <= b <= x[1] and n // 2 - (b + c + d) <= x[0]:
            ok = True
            ans = [n // 2 - (b + c + d), b, c, d]
if not ok:
    print(-1)
    exit()

fin = []
for i in range(n):
    cur = -1
    if y[i] == 0:
        if a[i] == 0:
            cur = 0
        else:
            cur = 1
    else:
        if a[i] == 0:
            cur = 2
        else:
            cur = 3
    if ans[cur] > 0:
        ans[cur] -= 1
        fin.append(i + 1)
print(*fin)


n = int(input())
y = list(map(int, list(input())))
a = list(map(int, list(input())))

x = [0, 0, 0, 0]
for i in range(n):
    if y[i] == 0:
        if a[i] == 0:
            x[0] += 1
        else:
            x[1] += 1
    else:
        if a[i] == 0:
            x[2] += 1
        else:
            x[3] += 1

ok = False
ans = []
for c in range(x[2] + 1):
    for d in range(x[3] + 1):
        b = x[1] + x[3] - c - 2 * d
        if 0 <= b + c + d <= n // 2 and 0 <= b <= x[1]:
            ok = True
            ans = [n // 2 - (b + c + d), b, c, d]
if n == 4990:
    print(x)
    print(ans)
if not ok:
    print(-1)
    exit()

fin = []
for i in range(n):
    cur = -1
    if y[i] == 0:
        if a[i] == 0:
            cur = 0
        else:
            cur = 1
    else:
        if a[i] == 0:
            cur = 2
        else:
            cur = 3
    if ans[cur] > 0:
        ans[cur] -= 1
        fin.append(i + 1)
print(*fin)


k=lambda:map(int,input().split())
l=lambda:list(k())
n = int(input())
pairs = [None for _ in range(n)]
cant = acros = clowns = both = 0
l1, l2 = input(), input()
# g1 = clowns, g2 = acros
# [cant, clowns, acros, both]
g1, g2 = [0, 0, 0, 0],[0, 0, 0, 0]
ans = [0]*n
for i in range(n):
	pairs[i] = (int(l1[i]), int(l2[i]), i+1)
	ans[i]=(pairs[i][0]+pairs[i][1]*2)
	if pairs[i][0]:
		if pairs[i][1]: both+=1
		else: clowns+=1
	else:
		if pairs[i][1]: acros+=1
		else:cant+=1
if (acros+clowns+both)% 2 == 1: # odd nr of 'good' things
	if acros == clowns == 0: # no way to compensate
		print(-1)
		raise SystemExit()
	if acros > clowns:
		acros -=1
		cant-=1
		g1[2]+=1
		g2[0]+=1
	else:
		clowns-=1
		cant-=1
		g2[1]+=1
		g1[0]+=1
val = min(acros, clowns) # divide
g1[1] += val
g2[2] += val
acros -= val
clowns -= val
if clowns > 0:
	valb = min(clowns, both)
	g1[1]+=valb
	g2[3]+=valb
	both -=valb
	clowns -= valb
elif acros > 0:
	valb = min(acros, both)
	g1[3] += valb
	g2[2] += valb
	acros-=valb
	both-=valb
valb = both//2 # divide both
g1[3]+=valb
g2[3]+=valb
both-=valb*2
valc = cant//2
g1[0]+=valc
g2[0]+=valc
cant-=valc*2
if cant > 0 or clowns > 0 or acros > 0 or both > 0:
	print(-1)
	raise ValueError(str(cant)+", "+str(clowns)+", "+str(acros)+", "+str(both))
else:
	for i in range(n):
		if g1[ans[i]] > 0:
			g1[ans[i]]-=1
			print(i+1, end=" ")
	print()


n = int(input())
pairs = [None for _ in range(n)]
cant = acros = clowns = both = 0
l1, l2 = input(), input()
# g1 = clowns, g2 = acros
# [cant, clowns, acros, both]
g1, g2 = [0, 0, 0, 0],[0, 0, 0, 0]
ans = [0]*n
for i in range(n):
	pairs[i] = (int(l1[i]), int(l2[i]), i+1)
	ans[i]=(pairs[i][0]+pairs[i][1]*2)
	if pairs[i][0]:
		if pairs[i][1]: both+=1
		else: clowns+=1
	else:
		if pairs[i][1]: acros+=1
		else:cant+=1
if (acros+clowns+both)% 2 == 1: # odd nr of 'good' things
	if acros == clowns == 0: # no way to compensate
		print(-1)
		raise SystemExit()
	if acros > clowns:
		acros -=1
		cant-=1
		g1[2]+=1
		g2[0]+=1
	else:
		clowns-=1
		cant-=1
		g2[1]+=1
		g1[0]+=1
val = min(acros, clowns) # divide
g1[1] += val
g2[2] += val
acros -= val
clowns -= val
if clowns > 0:
	valb = min(clowns, both)
	g1[1]+=valb
	g2[3]+=valb
	both -=valb
	clowns -= valb
elif acros > 0:
	valb = min(acros, both)
	g1[3] += valb
	g2[2] += valb
	acros-=valb
	both-=valb
valb = both//2 # divide both
g1[3]+=valb
g2[3]+=valb
both-=valb*2
valc = cant//2
g1[0]+=valc
g2[0]+=valc
cant-=valc*2
if cant > 0 or clowns > 0 or acros > 0 or both > 0:
	print(-1)
else:
	for i in range(n):
		if g1[ans[i]] > 0:
			g1[ans[i]]-=1
			print(i+1, end=" ")
	print()


k=lambda:map(int,input().split())
l=lambda:list(k())
n = int(input())
pairs = [None for _ in range(n)]
cant = acros = clowns = both = 0
l1, l2 = input(), input()
# g1 = clowns, g2 = acros
# [cant, clowns, acros, both]
g1, g2 = [0, 0, 0, 0],[0, 0, 0, 0]
ans = [0]*n
for i in range(n):
	pairs[i] = (int(l1[i]), int(l2[i]), i+1)
	ans[i]=(pairs[i][0]+pairs[i][1]*2)
	if pairs[i][0]:
		if pairs[i][1]: both+=1
		else: clowns+=1
	else:
		if pairs[i][1]: acros+=1
		else:cant+=1
if (acros+clowns+both)% 2 == 1: # odd nr of 'good' things
	if acros == clowns == 0: # no way to compensate
		print(-1)
		raise SystemExit()
	if acros > clowns:
		acros -=1
		cant-=1
		g1[2]+=1
		g2[0]+=1
	else:
		clowns-=1
		cant-=1
		g2[1]+=1
		g1[0]+=1
val = min(acros, clowns) # divide
g1[1] += val
g2[2] += val
acros -= val
clowns -= val
if clowns > 0:
	valb = min(clowns, both)
	g1[1]+=valb
	g2[3]+=valb
	both -=valb
	clowns -= valb
elif acros > 0:
	valb = min(acros, both)
	g1[3] += valb
	g2[2] += valb
	acros-=valb
	both-=valb
valb = both//2 # divide both
g1[3]+=valb
g2[3]+=valb
both-=valb*2
if clowns > 0:
	valc = min(clowns, cant)
	g2[1] += valc
	g1[0] +=valc
	clowns-=valc
	cant-=valc
if acros > 0:
	valc = min(acros, cant)
	g2[0] += valc
	g1[2] += valc
	acros-= valc
	cant -= valc
valc = cant//2
g1[0]+=valc
g2[0]+=valc
cant-=valc*2
if cant > 0 or clowns > 0 or acros > 0 or both > 0:
	print(-1)

else:
	for i in range(n):
		if g1[ans[i]] > 0:
			g1[ans[i]]-=1
			print(i+1, end=" ")
	print()


n = int(input())
n2 = n//2
c = input()
a = input()

only_clown = sum([1 for i in range(n) if c[i] == '1' and a[i] == '0'])
only_acrobat = sum([1 for i in range(n) if c[i] == '0' and a[i] == '1'])
both = sum([1 for i in range(n) if c[i] == '1' and a[i] == '1'])
neither = sum([1 for i in range(n) if c[i] == '0' and a[i] == '0'])

answer = []
def choose_n(n, ai, ci):
    idx = 0
    chosen = 0
    while chosen < n:
        if a[idx] == ai and c[idx] == ci:
            answer.append(idx+1)
            chosen += 1
        idx += 1

for choose_clowns_left in range(n2+1):
    for choose_only_clowns_left in range(0, min(choose_clowns_left, only_clown)+1):
        clown_right = only_clown - choose_only_clowns_left
        both_left = choose_clowns_left - choose_only_clowns_left

        both_right = both - both_left
        if both_right < 0: continue

        acrobat_right = choose_clowns_left - both_right
        acrobat_left = only_acrobat - acrobat_right
        if acrobat_right < 0 or acrobat_left < 0: continue
        if choose_clowns_left + clown_right > n2: continue
        if acrobat_left + choose_clowns_left > n2: continue
        neither_left = n2 - (choose_only_clowns_left + both_left - acrobat_left)
        if neither_left > neither: continue

        choose_n(choose_only_clowns_left, ai='0', ci='1')
        choose_n(both_left, ai='1', ci='1')
        choose_n(acrobat_left, ai='1', ci='0')
        choose_n(neither_left, ai='0', ci='0')

        print(*answer)
        exit()

print(-1)


n = int(input())
n2 = n//2
c = input()
a = input()

only_clown = sum([1 for i in range(n) if c[i] == '1' and a[i] == '0'])
only_acrobat = sum([1 for i in range(n) if c[i] == '0' and a[i] == '1'])
both = sum([1 for i in range(n) if c[i] == '1' and a[i] == '1'])
neither = sum([1 for i in range(n) if c[i] == '0' and a[i] == '0'])

answer = []
def choose_n(n, ai, ci):
    idx = 0
    chosen = 0
    while chosen < n:
        if a[idx] == ai and c[idx] == ci:
            answer.append(idx+1)
            chosen += 1
        idx += 1

for choose_clowns_left in range(n2+1):
    for choose_only_clowns_left in range(0, min(choose_clowns_left, only_clown)+1):
        both_left = choose_clowns_left - choose_only_clowns_left
        clown_right = only_clown - choose_only_clowns_left
        if both_left > both: continue

        both_right = both - both_left

        acrobat_right = choose_clowns_left - both_right
        acrobat_left = only_acrobat - acrobat_right
        if acrobat_right < 0 or acrobat_left < 0: continue
        if choose_clowns_left + clown_right > n2: continue
        if acrobat_left + choose_clowns_left > n2: continue
        neither_left = n2 - (choose_only_clowns_left + both_left + acrobat_left)
        if neither_left > neither: continue

        choose_n(choose_only_clowns_left, ai='0', ci='1')
        choose_n(both_left, ai='1', ci='1')
        choose_n(acrobat_left, ai='1', ci='0')
        choose_n(neither_left, ai='0', ci='0')

        print(*answer)
        exit()

print(-1)


n = int(input())
n2 = n//2
c = input()
a = input()

only_clown = sum([1 for i in range(n) if c[i] == '1' and a[i] == '0'])
only_acrobat = sum([1 for i in range(n) if c[i] == '0' and a[i] == '1'])
both = sum([1 for i in range(n) if c[i] == '1' and a[i] == '1'])
neither = sum([1 for i in range(n) if c[i] == '0' and a[i] == '0'])

answer = []
def choose_n(n, ai, ci):
    print(n, ai, ci)
    idx = 0
    chosen = 0
    while chosen < n:
        if a[idx] == ai and c[idx] == ci:
            answer.append(idx+1)
            chosen += 1
        idx += 1

for choose_clowns_left in range(n2+1):
    for choose_only_clowns_left in range(0, min(choose_clowns_left, only_clown)+1):
        print(choose_clowns_left, choose_only_clowns_left)
        clown_right = only_clown - choose_only_clowns_left
        both_left = choose_clowns_left - choose_only_clowns_left

        both_right = both - both_left
        if both_right < 0: continue

        acrobat_right = choose_clowns_left - both_right
        acrobat_left = only_acrobat - acrobat_right
        if acrobat_right < 0 or acrobat_left < 0: continue
        if choose_clowns_left + clown_right > n2: continue
        if acrobat_left + choose_clowns_left > n2: continue
        neither_left = n2 - (choose_only_clowns_left + both_left - acrobat_left)
        if neither_left > neither: continue

        choose_n(choose_only_clowns_left, ai='0', ci='1')
        choose_n(both_left, ai='1', ci='1')
        choose_n(acrobat_left, ai='1', ci='0')
        choose_n(neither_left, ai='0', ci='0')

        print(*answer)
        exit()

print(-1)


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

def neutral(zo,oz,oo,l):
    l3=l
    if l3%2==0:
        oz=oz+oo[:l3//2]
        zo=zo+oo[l3//2:]
    else:
        oz=oz+oo[:l3//2]+[zo[0]]
        zo=zo[1:]+oo[l3//2:]
    return [zo,oz]

if __name__=="__main__":
    n=intIn()
    c=stringIn()
    a=stringIn()
    zz,oo,zo,oz=[],[],[],[]
    for i in range(n):
        if c[i]=="0" and a[i]=="0":
            zz.append(i+1)
        elif c[i]=="0" and a[i]=="1":
            zo.append(i+1)
        elif c[i]=="1" and a[i]=="0":
            oz.append(i+1)
        else:
            oo.append(i+1)
    #print(zz,oz,zo,oo)

    l1,l2=len(zo),len(oz)
    l3,l4=len(oo),len(zz)

    if len(oz)==n or len(zo)==n:
        print(-1)
        exit(0)
    if len(oo)==n or len(zz)==n:
        print(*list(range(1,n//2+1)))
        exit(0)
    if len(oz)==0 and len(zo)==0:
        if l3%2==0:
            zo=zo+oo[:l3//2]+zz[:l4//2]
            oz=oz+oo[l3//2:]+zz[l4//2:]
            #print(zo,oz)
            oz.sort()
            print(*oz)
        else:
            print(-1)
        exit(0)

    diff=abs(l1-l2)
    if diff==0:
        zo,oz=neutral(zo,oz,oo,l3)
    else:
        d=abs(diff-l3)
        m=min(diff,l3)
        #print(d,m)
        if l2>l1:
            if diff>=l3:
                zo=zo+oo[:m]+oz[:d]
                oz=oz[d:]+oo[m:]
            else:
                zo=zo+oo[:m]
                oo=oo[m:]
                zo,oz=neutral(zo,oz,oo,d)
        else:
            if diff>=l3:
                oz=oz+oo[:m]+zo[:d]
                zo=zo[d:]+oo[m:]
            else:
                oz=oz+oo[:m]
                oo=oo[m:]
                zo,oz=neutral(zo,oz,oo,d)

    ll1,ll2=len(zo),len(oz)
    cn=n//2
    lr1=cn-ll1
    zo=zo+zz[:lr1]
    oz=oz+zz[lr1:]
    lll1,lll2=len(zo),len(oz)
    if len(zo)!=len(oz):
        print(-1)
    else:
        oz.sort()
        print(*oz)


import sys
DBG = not True
n = int(input())
cc = input()
aa = input()
c = []
a = []
for i in range(n):
    c.append(1 if cc[i]=='1' else 0)
    a.append(1 if aa[i]=='1' else 0)
e = [0,0,0,0]
g = [ [], [], [], [] ]
if DBG:
    print(c)
    print(a)

for i in range(n):
    if c[i]==0 and a[i]==0:
        e[0] += 1
        g[0].append(i)
    elif c[i]==0 and a[i]==1:
        e[1] += 1
        g[1].append(i)
    elif c[i]==1 and a[i]==0:
        e[2] += 1
        g[2].append(i)
    elif c[i]==1 and a[i]==1:
        e[3] += 1
        g[3].append(i)

for x2 in range(min(e[2],n//2)+1):  # can be C in (1)
  for x3 in range(min(e[3],n//2-x2)+1):  # can be C or A in (1)
      y3 = e[3] - x3   # can be C or A in (2)
      y1 = x2 + x3 - y3  # can be A in 2
      x1 = e[1] - y1
      x0 = n//2 - x1 - x2 - x3
      if 0 <= x1 and x1 <= e[1] and 0 <= x0 and x0 <= n//2:
          for i in range(x0):
              sys.stdout.write(str(g[0][i]+1) + ' ')
          for i in range(x1):
              sys.stdout.write(str(g[1][i]+1) + ' ')
          for i in range(x2):
              sys.stdout.write(str(g[2][i]+1) + ' ')
          for i in range(x3):
              sys.stdout.write(str(g[3][i]+1) + ' ')
          print('')
          sys.exit(0)
print(-1)


import sys
DBG = not True
n = int(input())
cc = input()
aa = input()
c = []
a = []
for i in range(n):
    c.append(1 if cc[i]=='1' else 0)
    a.append(1 if aa[i]=='1' else 0)
e = [0,0,0,0]
g = [ [], [], [], [] ]
if DBG:
    print(c)
    print(a)

for i in range(n):
    if c[i]==0 and a[i]==0:
        e[0] += 1
        g[0].append(i)
    elif c[i]==0 and a[i]==1:
        e[1] += 1
        g[1].append(i)
    elif c[i]==1 and a[i]==0:
        e[2] += 1
        g[2].append(i)
    elif c[i]==1 and a[i]==1:
        e[3] += 1
        g[3].append(i)

for x2 in range(min(e[2],n//2)+1):  # can be C in (1)
  for x3 in range(min(e[3],n//2-x2)+1):  # can be C or A in (1)
      y3 = e[3] - x3   # can be C or A in (2)
      y1 = x2 + x3 - y3  # can be A in 2
      x1 = e[1] - y1
      x0 = n//2 - x1 - x2 - x3
      if 0 <= x1 and x1 <= min(e[1],n//2) and 0 <= x0 and x0 <= min(e[0],n//2):
          for i in range(x0):
              sys.stdout.write(str(g[0][i]+1) + ' ')
          for i in range(x1):
              sys.stdout.write(str(g[1][i]+1) + ' ')
          for i in range(x2):
              sys.stdout.write(str(g[2][i]+1) + ' ')
          for i in range(x3):
              sys.stdout.write(str(g[3][i]+1) + ' ')
          print('')
          sys.exit(0)
print(-1)


n = int(input())
s1 = [int(i) for i in input()]
s2 = [int(i) for i in input()]
a = [[] for i in range(4)]
for i in range(n):
	a[s2[i] * 2 + s1[i]].append(i + 1)

def cal(a0, a2):
	nota0 = len(a[0]) - a0
	nota2 = len(a[2]) - a2
	nota1 = a0 + a2 - nota0
	a1 = len(a[1]) - nota1
	a3 = n // 2 - a0 - a1 - a2
	nota3 = len(a[3]) - a3
	if len(a[0]) < a0: return None
	if len(a[2]) < a2: return None
	if len(a[1]) < a1 or a1 < 0: return None
	if len(a[3]) < a3 or a3 < 0: return None
	if a1 + a3 != nota2 + nota3: return None
	return (a0, a1, a2, a3)

ans = None
for i in range(n // 2 + 1):
	if ans != None: break
	for j in range(n // 2 + 1):
		ans = cal(i, j)
		if ans != None: break

if ans == None:
	print(-1)
else:
	res = []
	a0, a1, a2, a3 = ans
	for i in range(a0): res.append(a[0][i])
	for i in range(a1): res.append(a[1][i])
	for i in range(a2): res.append(a[2][i])
	for i in range(a3): res.append(a[3][i])
	print(*res)


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e3;
mt19937 gen(84819314);
int p(int l,int r)
{
	return uniform_int_distribution<int>{l,r}(gen);
}
int main()
{
	int n,x,id,mx,nxt,a,y,z,i;
	cin>>n>>id>>x;
	cout<<"? "<<id<<endl;
	fflush(stdout);
	cin>>mx>>nxt;
	for(i=1;i<min(n,K);i++)
	{
		if(n>K)
			a=p(1,n-K+10);
		else
			a=p(1,n);
		cout<<"? "<<a<<endl;
		fflush(stdout);
		cin>>y>>z;
		if(y<=x && y>mx)
		{
			mx=y;
			id=a;
			nxt=z;
		}
	}
	//cerr<<mx<<"\n";
	while(mx<x)
	{
		if(nxt==-1)
		{
			cout<<"! -1"<<endl;
			fflush(stdout);
			return 0;
		}
		id=nxt;
		cout<<"? "<<id<<endl;
		fflush(stdout);
		cin>>mx>>nxt;
	}
	cout<<"! "<<mx<<endl;
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e3;
mt19937 gen(84819314);
int p(int l,int r)
{
	return uniform_int_distribution<int>{l,r}(gen);
}
int main()
{
	int n,x,id,mx,nxt,a,y,z,i;
	cin>>n>>id>>x;
	cout<<"? "<<id<<endl;
	cin>>mx>>nxt;
	for(i=1;i<K;i++)
	{
		a=p(1,min(n,n-K+10));
		cout<<"? "<<a<<endl;
		cin>>y>>z;
		if(y<=x && y>mx)
		{
			mx=y;
			id=a;
			nxt=z;
		}
	}
	//cerr<<mx<<"\n";
	while(mx<x)
	{
		if(nxt==-1)
		{
			cout<<"! -1"<<endl;
			return 0;
		}
		id=nxt;
		cout<<"? "<<id<<endl;
		cin>>mx>>nxt;
	}
	cout<<"! "<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e3;
mt19937 gen(84819314);
vector<int> poss;
int p(int l,int r)
{
	return uniform_int_distribution<int>{l,r}(gen);
}
int main()
{
	int n,x,id,mx,nxt,a,y,z,i;
	cin>>n>>id>>x;
	cout<<"? "<<id<<endl;
	fflush(stdout);
	cin>>mx>>nxt;
	for(i=1;i<=n;i++)
		poss.push_back(i);
	for(i=1;i<K && !poss.empty();i++)
	{
		int tmp=p(0,poss.size()-1);
		a=poss[tmp];
		swap(poss[tmp],poss.back());
		poss.pop_back();
		cout<<"? "<<a<<endl;
		fflush(stdout);
		cin>>y>>z;
		if(y<=x && y>mx)
		{
			mx=y;
			id=a;
			nxt=z;
		}
	}
	//cerr<<mx<<"\n";
	while(mx<x)
	{
		if(nxt==-1)
		{
			cout<<"! -1"<<endl;
			fflush(stdout);
			return 0;
		}
		id=nxt;
		cout<<"? "<<id<<endl;
		fflush(stdout);
		cin>>mx>>nxt;
		i++;
	}
	cout<<"! "<<mx<<endl;
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e3;
mt19937 gen(84819314);
int p(int l,int r)
{
	return uniform_int_distribution<int>{l,r}(gen);
}
int main()
{
	int n,x,id,mx,nxt,a,y,z,i;
	cin>>n>>id>>x;
	cout<<"? "<<id<<endl;
	fflush(stdout);
	cin>>mx>>nxt;
	for(i=1;i<min(n,K);i++)
	{
		a=p(1,min(n,n-K+10));
		cout<<"? "<<a<<endl;
		fflush(stdout);
		cin>>y>>z;
		if(y<=x && y>mx)
		{
			mx=y;
			id=a;
			nxt=z;
		}
	}
	//cerr<<mx<<"\n";
	while(mx<x)
	{
		if(nxt==-1)
		{
			cout<<"! -1"<<endl;
			fflush(stdout);
			return 0;
		}
		id=nxt;
		cout<<"? "<<id<<endl;
		fflush(stdout);
		cin>>mx>>nxt;
	}
	cout<<"! "<<mx<<endl;
	fflush(stdout);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e3;
mt19937 gen(84819314);
int p(int l,int r)
{
	return uniform_int_distribution<int>{l,r}(gen);
}
int main()
{
	int n,x,id,mx,nxt,a,y,z,i;
	cin>>n>>id>>x;
	cout<<"? "<<id<<endl;
	fflush(stdout);
	cin>>mx>>nxt;
	for(i=1;i<K;i++)
	{
		a=p(1,min(n,n-K+10));
		cout<<"? "<<a<<endl;
		fflush(stdout);
		cin>>y>>z;
		if(y<=x && y>mx)
		{
			mx=y;
			id=a;
			nxt=z;
		}
	}
	//cerr<<mx<<"\n";
	while(mx<x)
	{
		if(nxt==-1)
		{
			cout<<"! -1"<<endl;
			fflush(stdout);
			return 0;
		}
		id=nxt;
		cout<<"? "<<id<<endl;
		fflush(stdout);
		cin>>mx>>nxt;
	}
	cout<<"! "<<mx<<endl;
	fflush(stdout);
	return 0;
}


/*
 _     _
| |__ | |__   __ _  __ _ _   _  __ _
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

pii dp[N];

pii ask(ll int idx)
{
	if(dp[idx]!=mp(-1ll,-1ll)) return dp[idx];
	cout<<"? "<<idx<<endl;
	fflush(stdout);
	pii ret;
	cin>>ret.F>>ret.S;
	return dp[idx]=ret;
}

void print(ll int ans)
{
	cout<<"! "<<ans<<endl;
	fflush(stdout);
	exit(0);
}

int main()
{
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n,st,x;
		cin>>n>>st>>x;
		for(ll int i=1;i<=n;i++) dp[i]={-1,-1};
		pii maxi=ask(st);
		if(maxi.F>=x) print(maxi.F);
		ll int mini=hell;
		ll int cnt=888;
		while(cnt--)
		{
			ll int idx=rng()%n+1;
			pii tmp=ask(idx);
			if(tmp.F>=x) mini=min(mini,tmp.F);
			else maxi=max(maxi,tmp);
		}
		ll int idx=maxi.S;
		while(idx!=-1)
		{
			pii tmp=ask(idx);
			if(tmp.F>=x)
			{
				mini=min(mini,tmp.F);
				break;
			}
			idx=tmp.S;
		}
		print(mini);
	}
	return 0;
}


/*
 _     _
| |__ | |__   __ _  __ _ _   _  __ _
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

pii dp[N];

pii ask(ll int idx)
{
	if(dp[idx]!=mp(-1ll,-1ll)) return dp[idx];
	cout<<"? "<<idx<<endl;
	fflush(stdout);
	pii ret;
	cin>>ret.F>>ret.S;
	return dp[idx]=ret;
}

void print(ll int ans)
{
	if(ans==hell) ans=-1;
	cout<<"! "<<ans<<endl;
	fflush(stdout);
	exit(0);
}

int main()
{
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n,st,x;
		cin>>n>>st>>x;
		for(ll int i=1;i<=n;i++) dp[i]={-1,-1};
		pii maxi=ask(st);
		if(maxi.F>=x) print(maxi.F);
		ll int mini=hell;
		ll int cnt=888;
		while(cnt--)
		{
			ll int idx=rng()%n+1;
			pii tmp=ask(idx);
			if(tmp.F>=x) mini=min(mini,tmp.F);
			else maxi=max(maxi,tmp);
		}
		ll int idx=maxi.S;
		while(idx!=-1)
		{
			pii tmp=ask(idx);
			if(tmp.F>=x)
			{
				mini=min(mini,tmp.F);
				break;
			}
			idx=tmp.S;
		}
		print(mini);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

// RANDOM UTILITIES *********************************************************************
// -Source: https://github.com/jacklee1792/competitive-programming/blob/master/rand.h

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
T rint(T lo,T hi){return uniform_int_distribution<T>(lo,hi)(rng);}
template<class T>
T rreal(T lo,T hi){return uniform_real_distribution<T>(lo,hi)(rng);}

// **************************************************************************************

pair<int,int> qry(int i){
	cout<<"? "<<i<<endl;
	int val,nxt;
	cin>>val>>nxt;
	return {val,nxt};
}

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,s,x;cin>>n>>s>>x;
	int pt=s,bst=qry(s).first;
	// is it the first element?
	if(bst>=x){cout<<"! "<<bst<<endl;return 0;}
	// ok it's somewhere else
	for(int i=0;i<1000;i++){
		int npt=rint(1LL,n);
		int nbst=qry(npt).first;
		if(nbst>bst&&nbst<x){
			pt=npt;
			bst=nbst;
			// cerr<<"pt is now "<<pt<<"\n";
		}
	}
	// cerr<<"start walking, pt is "<<pt<<"\n";
	// walk up the thing
	while(pt!=-1&&bst<x){
		pair<int,int> pp=qry(pt);
		bst=pp.first;
		pt=pp.second;
	}
	if(bst<x)cout<<"! -1"<<endl;
	else cout<<"! "<<bst<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

// RANDOM UTILITIES *********************************************************************
// -Source: https://github.com/jacklee1792/competitive-programming/blob/master/rand.h

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
T rint(T lo,T hi){return uniform_int_distribution<T>(lo,hi)(rng);}
template<class T>
T rreal(T lo,T hi){return uniform_real_distribution<T>(lo,hi)(rng);}

// **************************************************************************************

pair<int,int> qry(int i){
	cout<<"? "<<i<<endl;
	int val,nxt;
	cin>>val>>nxt;
	return {val,nxt};
}

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,s,x;cin>>n>>s>>x;
	int pt=s,bst=qry(s).first;
	// is it the first element?
	if(bst>=x){cout<<"-1\n";return 0;}
	// ok it's somewhere else
	for(int i=0;i<1000;i++){
		int npt=rint(1LL,n);
		int nbst=qry(npt).first;
		if(nbst>bst&&nbst<x){
			pt=npt;
			bst=nbst;
			// cerr<<"pt is now "<<pt<<"\n";
		}
	}
	// cerr<<"start walking, pt is "<<pt<<"\n";
	// walk up the thing
	while(pt!=-1&&bst<x){
		pair<int,int> pp=qry(pt);
		bst=pp.first;
		pt=pp.second;
	}
	if(pt==-1)cout<<"! -1\n";
	else cout<<"! "<<bst<<"\n";
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

// RANDOM UTILITIES *********************************************************************
// -Source: https://github.com/jacklee1792/competitive-programming/blob/master/rand.h

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
T rint(T lo,T hi){return uniform_int_distribution<T>(lo,hi)(rng);}
template<class T>
T rreal(T lo,T hi){return uniform_real_distribution<T>(lo,hi)(rng);}

// **************************************************************************************

pair<int,int> qry(int i){
	cout<<"? "<<i<<endl;
	int val,nxt;
	cin>>val>>nxt;
	return {val,nxt};
}

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,s,x;cin>>n>>s>>x;
	int pt=s,bst=qry(s).first;
	// is it the first element?
	if(bst>=x){cout<<bst<<endl;return 0;}
	// ok it's somewhere else
	for(int i=0;i<1000;i++){
		int npt=rint(1LL,n);
		int nbst=qry(npt).first;
		if(nbst>bst&&nbst<x){
			pt=npt;
			bst=nbst;
			// cerr<<"pt is now "<<pt<<"\n";
		}
	}
	// cerr<<"start walking, pt is "<<pt<<"\n";
	// walk up the thing
	while(pt!=-1&&bst<x){
		pair<int,int> pp=qry(pt);
		bst=pp.first;
		pt=pp.second;
	}
	if(pt==-1)cout<<"! -1"<<endl;
	else cout<<"! "<<bst<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

// RANDOM UTILITIES *********************************************************************
// -Source: https://github.com/jacklee1792/competitive-programming/blob/master/rand.h

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
T rint(T lo,T hi){return uniform_int_distribution<T>(lo,hi)(rng);}
template<class T>
T rreal(T lo,T hi){return uniform_real_distribution<T>(lo,hi)(rng);}

// **************************************************************************************

pair<int,int> qry(int i){
	cout<<"? "<<i<<endl;
	int val,nxt;
	cin>>val>>nxt;
	return {val,nxt};
}

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,s,x;cin>>n>>s>>x;
	int pt=s,bst=qry(s).first;
	// is it the first element?
	if(bst>=x){cout<<"! "<<bst<<endl;return 0;}
	// ok it's somewhere else
	for(int i=0;i<1000;i++){
		int npt=rint(1LL,n);
		int nbst=qry(npt).first;
		if(nbst>bst&&nbst<x){
			pt=npt;
			bst=nbst;
			// cerr<<"pt is now "<<pt<<"\n";
		}
	}
	// cerr<<"start walking, pt is "<<pt<<"\n";
	// walk up the thing
	while(pt!=-1&&bst<x){
		pair<int,int> pp=qry(pt);
		bst=pp.first;
		pt=pp.second;
	}
	if(pt==-1)cout<<"! -1"<<endl;
	else cout<<"! "<<bst<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

// RANDOM UTILITIES *********************************************************************
// -Source: https://github.com/jacklee1792/competitive-programming/blob/master/rand.h

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
T rint(T lo,T hi){return uniform_int_distribution<T>(lo,hi)(rng);}
template<class T>
T rreal(T lo,T hi){return uniform_real_distribution<T>(lo,hi)(rng);}

// **************************************************************************************

pair<int,int> qry(int i){
	cout<<"? "<<i<<endl;
	int val,nxt;
	cin>>val>>nxt;
	return {val,nxt};
}

signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,s,x;cin>>n>>s>>x;
	int pt=s,bst=qry(s).first;
	// is it the first element?
	if(bst>=x){cout<<"-1"<<endl;return 0;}
	// ok it's somewhere else
	for(int i=0;i<1000;i++){
		int npt=rint(1LL,n);
		int nbst=qry(npt).first;
		if(nbst>bst&&nbst<x){
			pt=npt;
			bst=nbst;
			// cerr<<"pt is now "<<pt<<"\n";
		}
	}
	// cerr<<"start walking, pt is "<<pt<<"\n";
	// walk up the thing
	while(pt!=-1&&bst<x){
		pair<int,int> pp=qry(pt);
		bst=pp.first;
		pt=pp.second;
	}
	if(pt==-1)cout<<"! -1"<<endl;
	else cout<<"! "<<bst<<endl;
}


#include<cstdio>
#include<cstdlib>
#include<ctime>
inline int read()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')f=0;
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return f?x:-x;
}
int main()
{
	srand(time(0));
	int n,i,a,b,c,d,x;
	n=read();a=-1;b=read();x=read();
	for(i=1;i<=1000;++i)
	{
		printf("? %d\n",((rand()<<15)|rand())%n+1);
		fflush(stdout);
		c=read();d=read();
		if(c<x&&c>=a)a=c,b=d;
	}
	while(a<x)
	{
		if(b<0)return 0*puts("! -1");
		printf("? %d\n",b);
		fflush(stdout);
		a=read();b=read();
	}
	printf("! %d\n",a);
}


#include<cstdio>
#include<cstdlib>
#include<ctime>
inline int read()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')f=0;
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return f?x:-x;
}
int main()
{
	srand(time(0));
	int n,i,a,b,c,d,x;
	n=read();a=-1;b=read();x=read();
	for(i=1;i<=1000 ;++i)
	{
		printf("? %d\n",((rand()<<15))%n+1);
		fflush(stdout);
		c=read();d=read();
		if(c<x&&c>=a)a=c,b=d;
	}
	while(a<x)
	{
		if(b<0)return 0*puts("! -1");
		printf("? %d\n",b);
		fflush(stdout);
		a=read();b=read();
	}
	printf("! %d\n",a);
}


#include<cstdio>
#include<cstdlib>
#include<ctime>
inline int read()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')f=0;
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return f?x:-x;
}
int main()
{
	srand(time(0));
	int n,i,a,b,c,d,x;
	n=read();a=-1;b=read();x=read();
	for(i=1;i<=1000;++i)
	{
		printf("? %d\n",((rand()<<15|rand())%n+1);
		fflush(stdout);
		c=read();d=read();
		if(c<x&&c>=a)a=c,b=d;
// 		if(c<x && )     break;
	}
	while(a<x)
	{
		if(b<0)return 0*puts("! -1");
		printf("? %d\n",b);
		fflush(stdout);
		a=read();b=read();
	}
	printf("! %d\n",a);
}


#include<cstdio>
#include<cstdlib>
#include<ctime>
inline int read()
{
	int x,f=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')f=0;
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return f?x:-x;
}
int main()
{
	srand(time(0));
	int n,i,a,b,c,d,x;
	n=read();a=-1;b=read();x=read();
	for(i=1;i<=1000;++i)
	{
		printf("? %d\n",((rand()<<15))%n+1);
		fflush(stdout);
		c=read();d=read();
		if(c<x&&c>=a)a=c,b=d;
	}
	while(a<x)
	{
		if(b<0)return 0*puts("! -1");
		printf("? %d\n",b);
		fflush(stdout);
		a=read();b=read();
	}
	printf("! %d\n",a);
}


#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;
using li = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5e4 + 13;
const int Q1 = 990;
const int Q2 = 990;

mt19937 rnd(time(0));

pii a[N];

int main() {
    int n, start, x;
    cin >> n >> start >> x;

    for(int i = 0; i < n; i++)
    a[i] = {-1, -1};

    set<int> st;

    st.insert(start - 1);

    cout << "? " << start << endl;
    cin >> a[start - 1].f >> a[start - 1].s;
    a[start - 1].s--;

    while(st.size() < min(Q1, n)) {
        int i = rnd() % n;
        if(st.count(i))
            continue;

        cout << "? " << i + 1 << endl;

        cin >> a[i].f >> a[i].s;
        a[i].s--;

        st.insert(i);
    }

    int mx = -1, ans = -1;
    for(int i = 0; i < n; i++) {
        if(a[i].f == -1)
            continue;

        if(a[i].f >= x) {
            if(ans == -1 || a[ans].f > a[i].f)
                ans = i;
        } else {
            if(mx == -1 || a[mx].f < a[i].f)
                mx = i;
        }
    }

    if(mx == -1) {
        cout << "! " << a[start - 1].f << endl;
        return 0;
    }

    int cur = mx, pr = mx;
    while(true) {
        cout << "? " << cur + 1 << endl;

        cin >> a[cur].f >> a[cur].s;

        if(a[cur].f >= x) {
            cout << "! " << a[cur].f << endl;
            return 0;
        }

        if(a[cur].s == -1) {
            cout << "! " << -1 << endl;
            return 0;
        }

        cur = a[cur].s - 1;
    }
}


#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;
using li = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5e4 + 13;
const int Q1 = 990;
const int Q2 = 990;

mt19937 rnd(time(0));

pii a[N];

int main() {
    int n, start, x;
    cin >> n >> start >> x;

    for(int i = 0; i < n; i++)
    a[i] = {-1, -1};

    set<int> st;

    st.insert(start - 1);

    cout << "? " << start << endl;
    cin >> a[start - 1].f >> a[start - 1].s;
    a[start - 1].s--;

    while(st.size() < min(Q1, n)) {
        int i = rnd() % n;
        if(st.count(i))
            continue;

        cout << "? " << i + 1 << endl;

        cin >> a[i].f >> a[i].s;
        a[i].s--;

        st.insert(i);
    }

    int mx = -1, ans = -1;
    for(int i = 0; i < n; i++) {
        if(a[i].f == -1)
            continue;

        if(a[i].f >= x) {
            if(ans == -1 || a[ans].f > a[i].f)
                ans = i;
        } else {
            if(mx == -1 || a[mx].f < a[i].f)
                mx = i;
        }
    }

    if(mx == -1) {
        cout << "! " << start << endl;
        return 0;
    }

    int cur = mx, pr = mx;
    while(true) {
        cout << "? " << cur + 1 << endl;

        cin >> a[cur].f >> a[cur].s;

        if(a[cur].f >= x) {
            cout << "! " << a[cur].f << endl;
            return 0;
        }

        if(a[cur].s == -1) {
            cout << "! " << -1 << endl;
            return 0;
        }

        cur = a[cur].s - 1;
    }
}


#include <bits/stdc++.h>

#define f first
#define s second

using namespace std;
using li = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 5e4 + 13;
const int Q1 = 990;
const int Q2 = 990;

mt19937 rnd(time(0));

pii a[N];

int main() {
    int n, start, x;
    cin >> n >> start >> x;

    for(int i = 0; i < n; i++)
    a[i] = {-1, -1};

    set<int> st;

    st.insert(start - 1);

    cout << "? " << start << endl;
    cin >> a[start - 1].f >> a[start - 1].s;
    a[start - 1].s--;

    while(st.size() < min(Q1, n)) {
        int i = rnd() % n;
        if(st.count(i))
            continue;

        cout << "? " << i + 1 << endl;

        cin >> a[i].f >> a[i].s;
        a[i].s--;

        st.insert(i);
    }

    int mx = -1, ans = -1;
    for(int i = 0; i < n; i++) {
        if(a[i].f == -1)
            continue;

        if(a[i].f >= x) {
            if(ans == -1 || a[ans].f > a[i].f)
                ans = i;
        } else {
            if(mx == -1 || a[mx].f < a[i].f)
                mx = i;
        }
    }

    int cur = mx, pr = mx;
    while(true) {
        cout << "? " << cur + 1 << endl;

        cin >> a[cur].f >> a[cur].s;

        if(a[cur].f >= x) {
            cout << "! " << a[cur].f << endl;
            return 0;
        }

        if(a[cur].s == -1) {
            cout << "! " << -1 << endl;
            return 0;
        }

        cur = a[cur].s - 1;
    }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt - 1);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(head);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -1) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt - 1);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(head);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -2) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(idx);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -1) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(idx);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -1) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(idx);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -1) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;

  pair<int, int> best = ask(head);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -1) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt - 1);
}

void report (int ans) {
  cout << "! " << ans;
  exit(0);
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;
  head--;

  pair<int, int> best = ask(head);
  for (int i = 0; i < 1000; i++) {
    int idx = rand() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -2) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

pair<int, int> ask (int idx) {
  idx++;
  cout << "? " << idx << endl;

  int val, nxt;
  cin >> val >> nxt;
  if (val == -1 && nxt == -1) {
    exit(0);
  }
  return make_pair(val, nxt - 1);
}

void report (int ans) {
  cout << "! " << ans << endl;
  exit(0);
}

int rng () {
  int ans = 0;
  for (int i = 0; i < 20; i++) {
    ans *= 2;
    ans += rand() % 2;
  }
  return ans;
}

int main () {
  srand(time(NULL));

  int length, head, target;
  cin >> length >> head >> target;
  head--;

  pair<int, int> best = ask(head);
  for (int i = 0; i < 1000; i++) {
    int idx = rng() % length;
    pair<int, int> cur = ask(idx);
    if (cur.first < target) {
      best = max(best, cur);
    }
  }

  while (true) {
    if (best.first < target) {
      if (best.second == -2) {
        report(-1);
      }
      best = ask(best.second);
    } else {
      report(best.first);
    }
  }
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;

        ll g, id=s, val;
        rep(i,600){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;
        ll k=n/600;
        int done[n+1]={0};
        rep(i,600){
            g  = rand()%(k+1);
            g = 600*g + rand()%600;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id =z;
        rep(i,799){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;

        ll g, id=s, val;
        rep(i,600){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;
        ll k=n/600;
        int done[n+1]={0};
        rep(i,600){
            g  = rand()%(k+1);
            g = 600*g + rand()%600;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id =z;
        rep(i,799){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            else if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;
        if(n<2000){
            ll id=s, val;
            rep(i,n){
                cout<<"? "<<id<<endl;
                cin>>val>>id;
                if(val>=x){
                    cout<<"! "<<val<<endl;
                    return 0;
                }
                if(id==-1){
                    cout<<"! "<<-1<<endl;
                    return 0;
                }
            }
        }

        ll g, id=s, val;
        rep(i,600){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;
        ll k=n/600;
        int done[n+1]={0};
        rep(i,600){
            g  = rand()%(k+1);
            g = 600*g + rand()%600;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id=z;
        rep(i,799){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;
        if(n<2000){
            ll id=s, val;
            rep(i,n){
                cout<<"? "<<id<<endl;
                cin>>val>>id;
                if(val>=x){
                    cout<<"! "<<val<<endl;
                    return 0;
                }
                if(id==-1){
                    cout<<"! "<<-1<<endl;
                    return 0;
                }
            }
        }

        ll g, id=s, val;
        ll r=(ll)sqrt(n)+1;
        r = min(r, 665ll);
        rep(i,r){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;

        ll k=n/r;
        int done[n+1]={0};
        rep(i,r){
            g  = rand()%(k+1);
            g = k*g + rand()%r;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id=z;
        rep(i,(1999-2*r)){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;

        ll g, id=s, val;
        ll r=(ll)sqrt(n)+1;
        r = min(r, 665ll);
        rep(i,r){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;

        ll k=n/r;
        int done[n+1]={0};
        rep(i,r){
            g  = rand()%(k+1);
            g = k*g + rand()%r;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"! "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id=z;
        if(z==-1){
            cout<<"! "<<-1<<endl;
            return 0;
        }
        rep(i,(1999-2*r)){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;

        ll g, id=s, val;
        ll r=(ll)sqrt(n)+1;
        r = min(r, 665ll);
        rep(i,r){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;

        ll k=n/r;
        int done[n+1]={0};
        rep(i,r){
            g  = rand()%(k+1);
            g = k*g + rand()%r;
            if(g>n || done[g] || g==0){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id=z;
        if(z==-1){
            cout<<"! "<<-1<<endl;
            return 0;
        }
        rep(i,(1999-2*r)){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
    int T=1;
    //cin >> T;
    while(T--){
        ll n,s,x;
        cin>>n>>s>>x;

        ll g, id=s, val;
        rep(i,600){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
        ll mx=-1, z;
        ll k=n/600;
        int done[n+1]={0};
        rep(i,600){
            g  = rand()%(k+1);
            g = 600*g + rand()%600;
            if(g>n || done[g]){
                i--;
                continue;
            }
            done[g]=1;
            cout<<"? "<<g<<endl;
            cin>>val>>id;
            if(val==x){
                cout<<"? "<<x<<endl;
                return 0;
            }
            else if(val<x && val>mx){
                mx=val;
                z=id;
            }
        }
        id =z;
        rep(i,799){
            cout<<"? "<<id<<endl;
            cin>>val>>id;
            if(val>=x){
                cout<<"! "<<val<<endl;
                return 0;
            }
            else if(id==-1){
                cout<<"! "<<-1<<endl;
                return 0;
            }
        }
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


// In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;

const int MAXN = 5e4 + 100;
int a[MAXN], val[MAXN], nxt[MAXN], MAJ = 100;

int main() {
	ios_base::sync_with_stdio(false);
	int n, st, x;
	cin >> n >> st >> x; st--;

	for (int i = 0; i < n; i++)
		a[i] = i;
	random_shuffle(a, a + n);

	MAJ = min(n, MAJ);
	for (int i = 0; i < MAJ; i++) {
		cout << "? " << a[i] + 1 << endl;
		fflush(0);
		int X, Y;
		cin >> X >> Y;
		val[a[i]] = X, nxt[a[i]] = Y - 1;
	}

	for (int i = 0; i < MAJ; i++)
		if (val[a[i]] < x && (st == -1 ||  val[st] < val[a[i]]))
			st = a[i];

	cout << "? " << st + 1 << endl;
	fflush(0);
	int X, Y;
	cin >> X >> Y;
	if (X >= x) {
		cout << "! " << X << endl;
		return 0;
	}

	int idx = st, value = val[st];
	while (true) {
		int nxti, nxtv;
		cout << "? " << idx + 1 << endl;
		fflush(0);
		cin >> nxtv >> nxti;
		//cout << "@" << nxtv << ' ' << nxti << endl;
		if (nxti != -1)
			nxti--;

		if (value < x && nxtv >= x) {
			cout << "! " << nxtv << endl;
			return 0;
		}
		idx = nxti, value = nxtv;
		if (idx == -1) {
			cout << "! -1" << endl;
			return 0;
		}
	}

	return 0;
}


// In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;

const int maxn = 5e4 + 100;
int a[maxn], val[maxn], nxt[maxn];

int main() {
	srand(701);
	int n, st, x;
	cin >> n >> st >> x;
	st--;

	cout << "? " << st + 1 << endl;
	int X, Y;
	cin >> X >> Y;
	val[st] = X, nxt[st] = Y - 1;

	if (val[st] >= x) {
		cout << "! " << val[st] << endl;
		return 0;
	}

	for (int i = 0; i < n; i++)
		a[i] = i;
	random_shuffle(a, a + n);

	int maj = min(n, 200);
	for (int i = 0; i < maj; i++) {
		cout << "? " << a[i] + 1 << endl;
		cin >> X >> Y;
		val[a[i]] = X, nxt[a[i]] = Y - 1;
	}

	for (int i = 0; i < maj; i++)
		if (val[a[i]] < x && val[st] < val[a[i]])
			st = a[i];

	int idx = st, value = val[st];
	while (true) {
		int nxti, nxtv;
		cout << "? " << idx + 1 << endl;
		cin >> nxtv >> nxti;
		if (nxti != -1)
			nxti--;

		if (value < x && nxtv >= x) {
			cout << "! " << nxtv << endl;
			return 0;
		}
		idx = nxti, value = nxtv;
		if (idx == -1) {
			cout << "! -1" << endl;
			return 0;
		}
	}

	return 0;
}


// In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;

const int MAXN = 5e4 + 100;
int a[MAXN], val[MAXN], nxt[MAXN], MAJ = 300;

int main() {
	ios_base::sync_with_stdio(false);
	int n, st, x;
	cin >> n >> st >> x; st--;

	for (int i = 0; i < n; i++)
		a[i] = i;
	random_shuffle(a, a + n);

	MAJ = min(n, MAJ);
	for (int i = 0; i < MAJ; i++) {
		cout << "? " << a[i] + 1 << endl;
		fflush(0);
		int X, Y;
		cin >> X >> Y;
		val[a[i]] = X, nxt[a[i]] = Y - 1;
	}

	for (int i = 0; i < MAJ; i++)
		if (val[a[i]] < x && (st == -1 ||  val[st] < val[a[i]]))
			st = a[i];

	cout << "? " << st + 1 << endl;
	fflush(0);
	int X, Y;
	cin >> X >> Y;
	if (X >= x) {
		cout << "! " << X << endl;
		return 0;
	}

	int idx = st, value = val[st];
	while (true) {
		int nxti, nxtv;
		cout << "? " << idx + 1 << endl;
		fflush(0);
		cin >> nxtv >> nxti;
		//cout << "@" << nxtv << ' ' << nxti << endl;
		if (nxti != -1)
			nxti--;

		if (value < x && nxtv >= x) {
			cout << "! " << nxtv << endl;
			return 0;
		}
		idx = nxti, value = nxtv;
		if (idx == -1) {
			cout << "! -1" << endl;
			return 0;
		}
	}

	return 0;
}


// In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;

const int MAXN = 5e4 + 100;
int a[MAXN], val[MAXN], nxt[MAXN], MAJ = 600;

int main() {
	ios_base::sync_with_stdio(false);
	int n, st, x;
	cin >> n >> st >> x; st--;

	for (int i = 0; i < n; i++)
		a[i] = i;
	random_shuffle(a, a + n);

	MAJ = min(n, MAJ);
	for (int i = 0; i < MAJ; i++) {
		cout << "? " << a[i] + 1 << endl;
		fflush(0);
		int X, Y;
		cin >> X >> Y;
		val[a[i]] = X, nxt[a[i]] = Y - 1;
	}

	for (int i = 0; i < MAJ; i++)
		if (val[a[i]] < x && (st == -1 ||  val[st] < val[a[i]]))
			st = a[i];

	cout << "? " << st + 1 << endl;
	fflush(0);
	int X, Y;
	cin >> X >> Y;
	if (X >= x) {
		cout << "! " << X << endl;
		return 0;
	}

	int idx = st, value = val[st];
	while (true) {
		int nxti, nxtv;
		cout << "? " << idx + 1 << endl;
		fflush(0);
		cin >> nxtv >> nxti;
		//cout << "@" << nxtv << ' ' << nxti << endl;
		if (nxti != -1)
			nxti--;

		if (value < x && nxtv >= x) {
			cout << "! " << nxtv << endl;
			return 0;
		}
		idx = nxti, value = nxtv;
		if (idx == -1) {
			cout << "! -1" << endl;
			return 0;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == mk(-1, -1))
		exit(0);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	ask(start);
	for (int i = 0; i < min(900, n); i++) ask(index[i]);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi <= x && a[i].fi > a[current].fi)
			current = i;
	}

	for (int i = current; i != -1; i = a[i].se)
		if (ask(i).fi >= x) guess(a[i].fi);

	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(600, n);
	for (int i = 0; i < q; i++) ask(index[i]);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 2000 && i != -1; i = a[i].se, q++) {
		if (ask(i).fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);
	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(1100, n);
	for (int i = 0; i < q; i++) ask(index[i]);
	q += a[start].fi == -1;
	ask(start);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 2000 && i != -1; i = a[i].se, q++) {
		if (ask(i).fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);
	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(996, n);
	for (int i = 0; i < q; i++) ask(index[i]);
	q += a[start].fi == -1;
	ask(start);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 1999 && i != -1; i = a[i].se, q++) {
		if (ask(i).fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);
	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(1000, n);
	for (int i = 0; i < q; i++) ask(index[i]);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 2000 && i != -1; i = a[i].se, q++) {
		ask(i);
		if (a[i].fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);

	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(1000, n);
	for (int i = 0; i < q; i++) ask(index[i]);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].second; q < 2000 && i != -1; i = a[i].second, q++) {
		ask(i);
		if (a[i].fi >= x) guess(a[i].fi);
	}

	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min(1000, n);
	for (int i = 0; i < q; i++) ask(index[i]);
	ask(start);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 1999 && i != -1; i = a[i].se, q++) {
		if (ask(i).fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);
	guess(-1);
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 5e4 + 5, INF = 0x3f3f3f3f;

pii a[MAXN];

inline pii ask(int u) {
	if (a[u] != a[0]) return a[u];
	printf("? %d\n", u);
	fflush(stdout);
	int x, y; scanf("%d%d", &x, &y);
	a[u] = {x, y};
	if (a[u] == a[0]) while(1);
	return a[u];
}

inline void guess(int x) {
	printf("! %d\n", x);
	fflush(stdout);
	exit(0);
}

int main() {
	mset(a, -1);

	int n, start, x; scanf("%d%d%d", &n, &start, &x);
	vector<int> index(n);
	iota(index.begin(), index.end(), 1);
	shuffle(index.begin(), index.end(), rng);

	int q = min((int) sqrt(n) + 1, n);
	for (int i = 0; i < q; i++) ask(index[i]);

	int current = start;
	for (int i = 1; i <= n; i++) if (a[i].fi != -1) {
		if (a[i].fi < x && a[i].fi > a[current].fi) current = i;
		else if (a[i].fi == x) guess(a[i].fi);
	}

	for (int i = a[current].se; q < 2000 && i != -1; i = a[i].se, q++) {
		if (ask(i).fi >= x) guess(a[i].fi);
	}

	if (q == 2000) while(1);
	guess(-1);
}


#include <iostream>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <chrono>
#include <bitset>
#include <queue>
#include <math.h>
#include <stack>
#include <vector>
#include <string.h>
#include <random>

typedef long long ll;

const ll MOD = 1e9 + 7, INF = 1e18;

using namespace std;

vector < pair <int, int> > v;

set <int> s;

pair <int, int> query (int i)
{
	printf ("? %d\n", i);

	fflush (stdout);

	int a, b;

	scanf ("%d%d", &a, &b);

	return make_pair (a, b);
}

int main ()
{
	int n, start, x;

	cin >> n >> start >> x;

	s.insert (start);

	auto g = query (start);

	v.push_back (g);

	mt19937 rng(243);

    for (int i = 0; i < min (1000, n - 1); i++)
    {
    	int x = uniform_int_distribution <int> (1, n) (rng);

    	if (s.find (x) != s.end ())
    	{
    		i--;
    		continue;
    	}

    	auto k = query (x);

    	s.insert (x);

    	v.push_back (k);
    }

    sort (v.begin(), v.end());

    int k = lower_bound (v.begin(), v.end(), make_pair (x, -1)) - v.begin ();

    if (k == 0)
    {
    	printf ("! %d\n", v[0].first);
    	fflush (stdout);
    	return 0;
    }

    k--;

    g = v[k];

    while (g.first < x)
    {
    	if (g.second == -1)
    	{
    		printf ("! -1\n");
	    	fflush (stdout);
	    	return 0;
    	}
    	g = query (g.second);
    }

    printf ("! %d\n", g.first);
	fflush (stdout);
	return 0;

}


/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ;

// #define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii;
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ;
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

pii query(int idx){
    cout << "? " << idx << endl;
    int x, y;
    cin >> x >> y ;
    return mp(x, y);
}

void kek(int ans){
    cout << "! " << ans << endl ;
    exit(0) ;
}
void solve()
{
    int n , start , x ;
    cin >> n >> start >> x;
    vector<int> v(n); rep(i , n) v[i] = 1 + i;
    Randomize;
    random_shuffle(all(v));
    pii st = query(start);
    pii use = {-1 , -1};
    if(st.ff >= x){
        kek(st.ff);
    }else use = st ;
    rep(i , min(n , 999)){
        pii u = query(v[i]);
        if(u.ff < x){
            use = max(use , u);
        }
    }
    int idx = use.ss ;
    rep(i , 999){
        if(idx == -1) kek(-1);
        pii tmp = query(idx);
        if(tmp.ff >= x) kek(tmp.ff);
        else idx = tmp.ss ;
    }
}

int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ;

// #define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii;
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ;
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int remq = 1999;
pii query(int idx){
    remq--;
    cout << "? " << idx << endl;
    int x, y;
    cin >> x >> y ;
    return mp(x, y);
}

void kek(int ans){
    cout << "! " << ans << endl ;
    exit(0) ;
}
void solve()
{
    int n , start , x ;
    cin >> n >> start >> x;
    vector<int> v(n); rep(i , n) v[i] = 1 + i;
    v.erase(v.begin() + start - 1);
    Randomize;
    random_shuffle(all(v));
    pii st = query(start);
    pii use = {-1 , -1};
    if(st.ff >= x){
        kek(st.ff);
    }else use = st ;
    rep(i , min(sz(v) , 999)){
        pii u = query(v[i]);
        if(u.ff < x){
            use = max(use , u);
        }
    }
    int idx = use.ss ;
    rep(i , 3000){
        if(idx == -1) kek(-1);
        if(remq == 0) kek(-1);
        pii tmp = query(idx);
        if(tmp.ff >= x) kek(tmp.ff);
        else idx = tmp.ss ;
    }
    kek(-1);
}

int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ;

// #define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii;
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ;
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

int remq = 1999;
pii query(int idx){
    remq--;
    cout << "? " << idx << endl;
    int x, y;
    cin >> x >> y ;
    return mp(x, y);
}

void kek(int ans){
    cout << "! " << ans << endl ;
    exit(0) ;
}
void solve()
{
    int n , start , x ;
    cin >> n >> start >> x;
    vector<int> v(n); rep(i , n) v[i] = 1 + i;
    v.erase(v.begin() + start - 1);
    Randomize;
    shuffle(all(v) , rng);
    pii st = query(start);
    pii use = {-1 , -1};
    if(st.ff >= x){
        kek(st.ff);
    }else use = st ;
    rep(i , min(sz(v) , 999)){
        pii u = query(v[i]);
        if(u.ff < x){
            use = max(use , u);
        }
    }
    int idx = use.ss ;
    rep(i , 3000){
        if(idx == -1) kek(-1);
        if(remq == 0) kek(-1);
        pii tmp = query(idx);
        if(tmp.ff >= x) kek(tmp.ff);
        else idx = tmp.ss ;
    }
    kek(-1);
}

int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ;

// #define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii;
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ;
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

pii query(int idx){
    cout << "? " << idx << endl;
    int x, y;
    cin >> x >> y ;
    return mp(x, y);
}

void kek(int ans){
    cout << "! " << ans << endl ;
    exit(0) ;
}
void solve()
{
    int n , start , x ;
    cin >> n >> start >> x;
    vector<int> v(n); rep(i , n) v[i] = 1 + i;
    Randomize;
    random_shuffle(all(v));
    pii st = query(start);
    pii use = {-1 , -1};
    if(st.ff >= x){
        kek(st.ff);
    }else use = st ;
    rep(i , min(n , 999)){
        pii u = query(v[i]);
        if(u.ff < x){
            use = max(use , u);
        }
    }
    int idx = use.ss ;
    rep(i , 999){
        if(idx == -1) kek(-1);
        pii tmp = query(idx);
        if(tmp.ff >= x) kek(tmp.ff);
        else idx = tmp.ss ;
    }
    kek(-1);
}

int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}