/* 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;
    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 , 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;
}


/* 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(start);
    }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 , 1000){
        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;}

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 , 1000){
        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;
}


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

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5e4 + 4;

set <int> vals;

int x, n, s, used[N];
vector <int> perm;
int val, nxt;

void q(int num) {
    cout << "? " << num << endl;
    cin >> val >> nxt;
    vals.insert(val);
}

void ans() {
    if (vals.lower_bound(x) == vals.end()) {
        cout << "! -1" << endl;
    } else {
        cout << "! " << *vals.lower_bound(x) << endl;
    }
    exit(0);
}

void solve() {
    cin >> n >> s >> x;
    q(s);
    used[s] = 1;
    if (val >= x) {
        ans();
    }

    for (int i = 1; i <= n; ++i) {
        perm.push_back(i);
    }
    shuffle(perm.begin(), perm.end(), eng);

    for (int i = 0; i < 1998; ++i) {
        while (perm.size() && used[perm.back()]) {
            perm.pop_back();
        }
        if (perm.empty()) {
            ans();
        }
        int e = perm.back();
        perm.pop_back();

        int vals = val;
        int nxts = nxt;

        q(e);
        used[e] = 1;

        if (val > x) {
            used[nxt] = 1;
            val = vals;
            nxt = nxts;
        } else {
            if (val > vals) {
                s = e;
            } else {
                val = vals;
                nxt = nxts;
            }
        }
    }

    ans();
}

int main() {
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}


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

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5e4 + 4;

set <int> valset;

int x, n, s, used[N];
vector <int> perm;
int val, nxt, quest = 1999;

void q(int num) {
    if (num == -1) {
        return;
    }
    if (!used[num]) {
        if (quest > 0) {
            --quest;
            used[num] = 1;
            cout << "? " << num << endl;
            cin >> val >> nxt;
            valset.insert(val);
        }
    }
}

void ans() {
    if (valset.lower_bound(x) == valset.end()) {
        cout << "! -1" << endl;
    } else {
        cout << "! " << *valset.lower_bound(x) << endl;
    }
    exit(0);
}

void solve() {
    cin >> n >> s >> x;
    q(s);

    for (int i = 1; i <= n; ++i) {
        perm.push_back(i);
    }
    shuffle(perm.begin(), perm.end(), eng);

    while(true) {
        while (perm.size() && used[perm.back()]) {
            perm.pop_back();
        }
        if (perm.empty()) {
            break;
        }
        int e = perm.back();
        perm.pop_back();

        int vals = val;
        int nxts = nxt;

        q(e);

        if (val > x) {
            q(nxts);
        } else {
            if (val > vals) {
                s = e;
            } else {
                q(nxts);
            }
        }
    }

    ans();
}

int main() {
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}


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

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5e4 + 4;

set <int> valset;

int x, n, s, used[N];
vector <int> perm;
int val, nxt, quest = 1998;

void q(int num) {
    if (quest-- > 0 && !used[num]) {
        used[num] = 1;
        cout << "? " << num << endl;
        cin >> val >> nxt;
        valset.insert(val);
    }
}

void ans() {
    if (valset.lower_bound(x) == valset.end()) {
        cout << "! -1" << endl;
    } else {
        cout << "! " << *valset.lower_bound(x) << endl;
    }
    exit(0);
}

void solve() {
    cin >> n >> s >> x;
    q(s);

    for (int i = 1; i <= n; ++i) {
        perm.push_back(i);
    }
    shuffle(perm.begin(), perm.end(), eng);

    while(true) {
        while (perm.size() && used[perm.back()]) {
            perm.pop_back();
        }
        if (perm.empty()) {
            break;
        }
        int e = perm.back();
        perm.pop_back();

        int vals = val;
        int nxts = nxt;

        q(e);

        if (val > x) {
            q(nxts);
        } else {
            if (val > vals) {
                s = e;
            } else {
                q(nxts);
            }
        }
    }

    ans();
}

int main() {
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, st, x;
const int N = 2000;
vector<int> alive;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<int, int> query(int id) {
  cout << "? " << id + 1 << endl;
  int nxt, val;
  cin >> val >> nxt;
  nxt--;
  alive[id] = 1;
  return make_pair(val, nxt);
}

int main() {
  cin >> n >> st >> x;
  st--;
  alive.resize(n);
  vector<int> nxt(n);
  vector<int> val(n);
  pair<int, int> foo = query(st);
  nxt[st] = foo.second; val[st] = foo.first;
  int cnt = 1;
  range(i, 1, N / 2) {
    if(cnt >= n - N / 2) break;
    int cur = uniform_int_distribution<int>(0, n - 1)(rng);
    while(alive[cur]) cur = uniform_int_distribution<int>(0, n - 1)(rng);
    foo = query(cur);
    nxt[cur] = foo.second;
    val[cur] = foo.first;
  }
  int id = -1;
  range(i, 0, n) {
    if(!alive[i] || val[i] > x) continue;
    if(id == -1 || val[i] > val[id]) id = i;
  }
  if(id == -1) {
    cout << "! " << val[st] << endl;
    return 0;
  }
  int res = id;
  while(val[res] < x) {
    res = nxt[res];
    if(res == -1) {
      cout << "! -1" << endl;
      return 0;
    }
    foo = query(res);
    nxt[res] = foo.second;
    val[res] = foo.first;
  }
  cout << "! " << val[res] << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, st, x;
const int N = 2000;
vector<int> alive;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<int, int> query(int id) {
  cout << "? " << id + 1 << endl;
  int nxt, val;
  cin >> val >> nxt;
  nxt--;
  alive[id] = 1;
  return make_pair(val, nxt);
}

int main() {
  cin >> n >> st >> x;
  st--;
  alive.resize(n);
  vector<int> nxt(n);
  vector<int> val(n);
  pair<int, int> foo = query(st);
  nxt[st] = foo.second; val[st] = foo.first;
  int cnt = 1;
  range(i, 1, N / 2) {
    if(cnt >= n - N / 2) break;
    int cur = uniform_int_distribution<int>(0, n - 1)(rng);
    while(alive[cur]) cur = uniform_int_distribution<int>(0, n - 1)(rng);
    foo = query(cur);
    nxt[cur] = foo.second;
    val[cur] = foo.first;
    cnt++;
  }
  int id = -1;
  range(i, 0, n) {
    if(!alive[i] || val[i] > x) continue;
    if(id == -1 || val[i] > val[id]) id = i;
  }
  if(id == -1) {
    cout << "! " << val[st] << endl;
    return 0;
  }
  int res = id;
  while(val[res] < x) {
    res = nxt[res];
    if(res == -1) {
      cout << "! -1" << endl;
      return 0;
    }
    foo = query(res);
    nxt[res] = foo.second;
    val[res] = foo.first;
  }
  cout << "! " << val[res] << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, st, x;
const int N = 2000;
vector<int> alive;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
pair<int, int> query(int id) {
  cout << "? " << id + 1 << endl;
  int nxt, val;
  cin >> val >> nxt;
  nxt--;
  alive[id] = 1;
  return make_pair(val, nxt);
}

int main() {
  cin >> n >> st >> x;
  st--;
  alive.resize(n);
  vector<int> nxt(n);
  vector<int> val(n);
  pair<int, int> foo = query(st);
  nxt[st] = foo.second; val[st] = foo.first;
  int cnt = 1;
  range(i, 1, N / 2) {
    if(cnt >= n - N / 2) break;
    int cur = uniform_int_distribution<int>(0, n - 1)(rng);
    while(alive[cur]) cur = uniform_int_distribution<int>(0, n - 1)(rng);
    foo = query(cur);
    nxt[cur] = foo.second;
    val[cur] = foo.first;
    cnt++;
  }
  int id = -1;
  range(i, 0, n) {
    if(!alive[i] || val[i] > x) continue;
    if(id == -1 || val[i] > val[id]) id = i;
  }
  if(id == -1) {
    cout << "! " << val[st] << endl;
    return 0;
  }
  int res = id;
  while(val[res] < x) {
    res = nxt[res];
    if(res == -2) {
      cout << "! -1" << endl;
      return 0;
    }
    foo = query(res);
    nxt[res] = foo.second;
    val[res] = foo.first;
  }
  cout << "! " << val[res] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define X first
#define Y second

auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);

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

    int ans = -1, prev, aa, bb, q = 1000, aaa;

    while (q--) {
        int k = uniform_int_distribution<int>(1, n)(rng);
        if (q == 999) k = s;
        cout << "? " << k << endl;
        cin >> aa >> bb;
        if (q == 999) aaa = aa;
        fflush(stdout);
        if (aa < x) {
            if (ans < aa) {
                ans = aa;
                prev = bb;
            }
        }
    }

    q = 999;
    bool is = true;
    if (aaa >= x) {
        cout << "! " << aaa << endl;
        fflush(stdout);
        return 0;
    }

    if (prev == -1) {
        cout << "! " << -1 << endl;
        fflush(stdout);
        return 0;
    }

    while (q--) {
        cout << "? " << prev << endl;
        cin >> aa >> bb;
        fflush(stdout);
        if (aa >= x) {
            is = false;
            break;
        }
        if (bb == -1) break;
        prev = bb;

    }

    if (is) aa = -1;
    cout << "! " << aa << endl;
    fflush(stdout);
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define X first
#define Y second

auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);

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

    int ans = -1, prev, aa, bb, q = 1000, aaa;

    while (q--) {
        int k = uniform_int_distribution<int>(1, n)(rng);
        if (q == 999) k = s;
        cout << "? " << k << endl;
        cin >> aa >> bb;
        if (q == 999) aaa = aa;
        fflush(stdout);
        if (aa < x) {
            if (ans < aa) {
                ans = aa;
                prev = bb;
            }
        }
    }

    q = 999;
    bool is = true;
    if (aaa >= x) {
        cout << "! " << aaa << endl;
        fflush(stdout);
        return 0;
    }

    while (q--) {
        cout << "? " << prev << endl;
        cin >> aa >> bb;
        fflush(stdout);
        if (aa >= x) {
            is = false;
            break;
        }
        if (bb == -1) break;
        prev = bb;

    }

    if (is) aa = -1;
    cout << "! " << aa << endl;
    fflush(stdout);
    return 0;

}


//Finite Disappointment and Infinite Hope
#include <bits/stdc++.h>
using namespace std;
#define help ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.first<<","<<v.second<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x:c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
const ll N=1e6+5,mod=998244353;
int main(){
help
    srand(time(0));
    ll n,s,x,val,nxt;cin>>n>>s>>x;
    ll sval=-1;
    for(ll i=0;i<700;i++){
        ll pos=(rand()*10 + rand() )%n + 1;
        cout<<"? "<<pos<<endl;
        cin>>val>>nxt;
        if(val<x && val>sval){
            s=pos;
            sval=val;
        }
    }
    while(1){
        cout<<"? "<<s<<endl;
        cin>>val>>nxt;
        if(val>=x || nxt==-1){
            cout<<"! "<<(val<x?-1:val)<<endl;
            return 0;
        }
        s=nxt;
    }
}


#include <cstdlib>
#include <cstdio>
#include <ctime>

using namespace std;

int main() {

    srand(time(NULL));

    int n, start, x;

    scanf("%d%d%d", &n, &start, &x);

    int lower = start, lowerVal = 0;
    int upper = -1, upperVal = 1 << 31;
    int next, value;

    for(int i = 0; i < 1000; i++) {
        int currentNode = (rand() % n) + 1;
        printf("? %d\n", currentNode);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value > lowerVal && value <= x)
            lower = currentNode, lowerVal = value;

        if(value < upperVal && value > x)
            upper = currentNode, upperVal = value;
    }

    int lastValue = lowerVal;
    int current = lower;
    while(current != -1 && current != upper) {
        printf("? %d\n", current);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value >= x) {
            printf("! %d\n", value);
            return 0;
        }

        lastValue = value;
        current = next;
    }

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <ctime>

using namespace std;

int main() {

    srand(time(NULL));

    int n, start, x;

    scanf("%d%d%d", &n, &start, &x);

    int lower = start, lowerVal = 0;
    int upper = -1, upperVal = 1 << 31;
    int next, value;

    for(int i = 0; i < 1000; i++) {
        int currentNode = (rand() % n) + 1;
        printf("? %d\n", currentNode);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value > lowerVal && value <= x)
            lower = currentNode, lowerVal = value;

        if(value < upperVal && value > x)
            upper = currentNode, upperVal = value;
    }

    int current = lower;
    while(current != -1 && current != upper) {
        printf("? %d\n", current);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value >= x) {
            printf("! %d\n", value);
            return 0;
        }

        current = next;
    }

    printf("! -1\n");

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <ctime>

using namespace std;

int main() {

    srand(time(NULL));

    int n, start, x;

    scanf("%d%d%d", &n, &start, &x);

    int lower = start, lowerVal = 0;
    int upper = -1, upperVal = 1 << 31;
    int next, value;

    for(int i = 0; i < 1000; i++) {
        int currentNode = (rand() % n) + 1;
        printf("? %d\n", currentNode);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value > lowerVal && value <= x)
            lower = currentNode, lowerVal = value;

        if(value < upperVal && value > x)
            upper = currentNode, upperVal = value;
    }

    int current = lower;
    while(current != -1 && current != upper) {
        printf("? %d\n", current);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value >= x) {
            printf("! %d\n", value);
            return 0;
        }

        lastValue = value;
        current = next;
    }

    printf("! -1\n");

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <ctime>

using namespace std;

int main() {

    srand(time(NULL));

    int n, start, x;

    scanf("%d%d%d", &n, &start, &x);

    int lower = start, lowerVal = 0;
    int upper = -1, upperVal = 1 << 31;
    int next, value;

    for(int i = 0; i * i < n; i++) {
        int currentNode = ((rand() * rand()) % n) + 1;
        printf("? %d\n", currentNode);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value > lowerVal && value <= x)
            lower = currentNode, lowerVal = value;

        if(value < upperVal && value > x)
            upper = currentNode, upperVal = value;
    }

    int current = lower;
    while(current != -1 && current != upper) {
        printf("? %d\n", current);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value >= x) {
            printf("! %d\n", value);
            return 0;
        }

        current = next;
    }

    printf("! -1\n");

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <ctime>

using namespace std;

int main() {

    srand(time(NULL));

    int n, start, x;

    scanf("%d%d%d", &n, &start, &x);

    int lower = start, lowerVal = 0;
    int upper = -1, upperVal = 1 << 31;
    int next, value;

    for(int i = 0; i * i < n; i++) {
        int currentNode = (rand() % n) + 1;
        printf("? %d\n", currentNode);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value > lowerVal && value <= x)
            lower = currentNode, lowerVal = value;

        if(value < upperVal && value > x)
            upper = currentNode, upperVal = value;
    }

    int current = lower;
    while(current != -1 && current != upper) {
        printf("? %d\n", current);
        fflush(stdout);
        scanf("%d%d", &value, &next);

        if(value >= x) {
            printf("! %d\n", value);
            return 0;
        }

        current = next;
    }

    printf("! -1\n");

    return 0;
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,start,x;
	cin>>n>>start>>x;
	cout<<"? "<<start<<endl;
	int val,id;
	cin>>val>>id;
	int place = -1;
	int max1;
	if(val <= x){
		max1 = val;
		place = start;
	}
	else{
		cout<<"! "<<val<<endl;
		return 0;
	}
	rep(i,999){
		int z = rng()%n;
		cout<<"? "<<z+1<<endl;
		cin>>val>>id;
		if(val <= x){
			max1 = max(max1,val);
			if(max1 == val){
				place = z+1;
			}
		}
	}
	int cur = place;
	int next;
	rep(i,999){
		cout<<"? "<<cur<<endl;
		cin>>val>>next;
		if(val >= x){
			cout<<"! "<<val<<endl;
			return 0;
		}
		cur = next;
		if(next == -1)break;
	}
	cout<<"! "<<"-1"<<endl;
	return 0;
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > >
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,start,x;
	cin>>n>>start>>x;
	cout<<"? "<<start<<endl;
	int val,id;
	cin>>val>>id;
	int place = -1;
	int max1;
	if(val <= x){
		max1 = val;
		place = start;
	}
	else{
		cout<<"! "<<val<<endl;
		return 0;
	}
	rep(i,999){
		int z = rng()%n;
		cout<<"? "<<z+1<<endl;
		cin>>val>>id;
		if(val <= x){
			max1 = max(max1,val);
			if(max1 == val){
				place = z;
			}
		}
	}
	int cur = place;
	int next;
	rep(i,999){
		cout<<"? "<<cur<<endl;
		cin>>val>>next;
		if(val >= x){
			cout<<"! "<<val<<endl;
			return 0;
		}
		cur = next;
		if(next == -1)break;
	}
	cout<<"! "<<"-1"<<endl;
	return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x || bestn == -1)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = ((rand()<<10+rand())%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<-1<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(time(NULL));
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<-1<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = rand()%n+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans, ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    int ans, ansn;
    cin>>ans, ansn;
    if(ans > x || ansn == -1)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    best = ans;
    bestn = ansn;
  }
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int f = (((((long long)rand())<<12)+(long long)rand())%n)+1;
    cout<<"? "<<f<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(time(NULL));
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  for(int i = 0; i < 1000; i++)
  {
    int x = rand()%n+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans, ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    int ans, ansn;
    cin>>ans, ansn;
    if(ans > x || ansn == -1)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    best = ans;
  }
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(time(NULL));
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 1000; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<-1<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  if(n > 1000)
    cout<<best<<" "<<bestn<<endl;
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<-1<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  cout<<best<<" "<<bestn<<endl;
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<-1<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (((((long long)rand())<<12)+(long long)rand())%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x || bestn == -1)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x || bestn == -1)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
  }
  return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (rand()%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  while(1)
  {
    cout<<"? "<<bestn<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans > x || ansn == -1)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    best = ans;
    bestn = ansn;
  }
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = (((rand()<<12)+rand())%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


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

using namespace std;

int n, s, x;

int best = -1, bestn;

int main(int argc, char const *argv[]) {
  cin>>n>>s>>x;
  srand(87879);
  bestn = s;
  for(int i = 0; i < 1000; i++)
  {
    int x = ((rand()<<16+rand())%n)+1;
    cout<<"? "<<x<<endl;
    int ans, ansn;
    cin>>ans>>ansn;
    if(ans <= x && ans > best)
    {
      best = ans;
      bestn = ansn;
    }
  }
  if(best >= x)
  {
    cout<<"! "<<best<<endl;
    return 0;
  }
  if(bestn == -1)
  {
    cout<<"! "<<-1<<endl;
    return 0;
  }
  for(int i = 0; i < 999; i++)
  {
    cout<<"? "<<bestn<<endl;
    cin>>best>>bestn;
    if(best >= x)
    {
      cout<<"! "<<best<<endl;
      return 0;
    }
    if(bestn == -1)
    {
      cout<<"! "<<-1<<endl;
      return 0;
    }
  }
  cout<<"! "<<best<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define pdd pair<double, double>
#define double long double
#define F first
#define S second
using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

bool f[50005];

int32_t main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n, s, d;
   cin >> n >> s >> d;
   int q = 1000, rs = 0, idx = s;
   while(q --){
      int x = rnd() % n + 1;
      if(!f[x]){
         f[x] = true;
         cout << "? " << x << endl;
         int v, nxt;
         cin >> v >> nxt;
         if(v <= d && v >= rs)
            rs = v, idx = x;
      }
   }
   q = 999;
   while(q -- && idx != -1){
      cout << "? " << idx << endl;
      int v, nxt;
      cin >> v >> nxt;
      if(v >= d){
         rs = v;
         break;
      }
      idx = nxt;
   }
   if(rs < d)
      rs = -1;
   cout << "! " << rs;
}


#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define pdd pair<double, double>
#define double long double
#define F first
#define S second
using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

bool f[50005];

int32_t main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n, s, d;
   cin >> n >> s >> d;
   int q = 1000, rs = 0, idx = 0;
   while(q --){
      int x = rnd() % n + 1;
      if(!f[x]){
         f[x] = true;
         cout << "? " << x << endl;
         int v, nxt;
         cin >> v >> nxt;
         if(v <= d && v >= rs)
            rs = v, idx = x;
      }
   }
   q = 999;
   while(q -- && idx != -1){
      cout << "? " << idx << endl;
      int v, nxt;
      cin >> v >> nxt;
      if(v >= d){
         rs = v;
         break;
      }
      idx = nxt;
   }
   cout << "! " << rs;
}


#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define pdd pair<double, double>
#define double long double
#define F first
#define S second
using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

bool f[50005];

int32_t main(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n, s, d;
   cin >> n >> s >> d;
   int q = 1000, rs = 0, idx = 0;
   while(q --){
      int x = rnd() % n + 1;
      if(!f[x]){
         f[x] = true;
         cout << "? " << x << endl;
         int v, nxt;
         cin >> v >> nxt;
         if(v <= d && v >= rs)
            rs = v, idx = x;
      }
   }
   q = 999;
   while(q -- && idx != -1){
      cout << "? " << idx << endl;
      int v, nxt;
      cin >> v >> nxt;
      if(v >= d){
         rs = v;
         break;
      }
      idx = nxt;
   }
   if(rs < d)
      rs = -1;
   cout << "! " << rs;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
using namespace std;
int n,start,x;
int a[50010];
pair<int,int>ask(int x)
{
	printf("? %d\n",x);
	fflush(stdout);
	int val,nxt;
	scanf("%d%d",&val,&nxt);
	return make_pair(val,nxt);
}
int val,nxt;
int main()
{
	srand(time(0));
	scanf("%d%d%d",&n,&start,&x);
	for(int i=1;i<start;i++)a[i]=i;
	for(int i=start+1;i<=n;i++)a[i-1]=i;
	random_shuffle(a+1,a+n);
	pair<int,int>t=ask(start);
	val=t.first;nxt=t.second;
	for(int i=1;i<n && i<1000;i++)
	{
		t=ask(a[i]);
		if(t.first<=x && t.first>val)val=t.first,nxt=t.second;
	}
	while(val<x)
	{
		if(nxt==-1)
		{
			printf("! -1");
			fflush(stdout);
			return 0;
		}
		t=ask(nxt);
		val=t.first;nxt=t.second;
	}
	printf("! %d",val);
	fflush(stdout);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
using namespace std;
int n,start,x;
int a[50010];
pair<int,int>ask(int x)
{
	printf("? %d\n",x);
	fflush(stdout);
	int val,nxt;
	scanf("%d%d",&val,&nxt);
	return make_pair(val,nxt);
}
int val,nxt;
int main()
{
	srand(time(0));
	scanf("%d%d%d",&n,&start,&x);
	for(int i=1;i<start;i++)a[i]=i;
	for(int i=start+1;i<=n;i++)a[i-1]=i;
	random_shuffle(a+1,a+n);
	pair<int,int>t=ask(start);
	val=t.first;nxt=t.second;
	for(int i=2;i<n && i<1000;i++)
	{
		t=ask(a[i]);
		if(t.first<=x && t.first>val)val=t.first,nxt=t.second;
	}
	while(val<x)
	{
		if(nxt==-1)
		{
			printf("! -1");
			fflush(stdout);
			return 0;
		}
		t=ask(nxt);
		val=t.first;nxt=t.second;
	}
	printf("! %d",val);
	fflush(stdout);
	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans, total;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	if (n < 100) total = n;
	else total = min(1000, n / 2);
	for (i = 0; i < total; i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << "? " << curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	if (v[start] >= x) ans = v[start];
	else if (maxid == -1) ans = -1;
	else {
		curr = maxid;
		ans = v[curr];
		while (v[curr] < x) {
			if (next[curr] == -1) {
				ans = -1;
				break;
			}
			cout << "? " << next[curr] << "\n";
			cout.flush();
			cin >> v[next[curr]] >> next[next[curr]];

			curr = next[curr];
			ans = v[curr];
		}
	}

	cout << "! " << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < min(1000, n); i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << "? " <<  curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	if (maxid == -1) ans = -1;
	else {
		curr = maxid;
		while (v[curr] < x) {
			if (next[curr] == -1) {
				ans = -1;
				break;
			}
			cout << "? " << next[curr] << "\n";
			cout.flush();
			cin >> v[next[curr]] >> next[next[curr]];

			curr = next[curr];
			ans = v[curr];
		}
	}

	cout << "! " << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < n; i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	curr = maxid;
	while (v[curr] < x) {
		if (next[curr] == -1) {
			ans = -1;
			break;
		}
		curr = next[curr];
		ans = v[curr];
	}

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < min(1000, n / 2); i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << "? " << curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	if (v[start] >= x) ans = v[start];
	else if (maxid == -1) ans = -1;
	else {
		curr = maxid;
		ans = v[curr];
		while (v[curr] < x) {
			if (next[curr] == -1) {
				ans = -1;
				break;
			}
			cout << "? " << next[curr] << "\n";
			cout.flush();
			cin >> v[next[curr]] >> next[next[curr]];

			curr = next[curr];
			ans = v[curr];
		}
	}

	cout << "! " << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < n; i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	curr = maxid;
	while (v[curr] < x) {
		if (next[curr] == -1) {
			ans = -1;
			break;
		}
		cout << next[curr] << "\n";
		cout.flush();
		cin >> v[next[curr]] >> next[next[curr]];

		curr = next[curr];
		ans = v[curr];
	}

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < min(1000, n); i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << "? " <<  curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	if (maxid == -1) ans = -1;
	else {
		curr = maxid;
		ans = v[curr];
		while (v[curr] < x) {
			if (next[curr] == -1) {
				ans = -1;
				break;
			}
			cout << "? " << next[curr] << "\n";
			cout.flush();
			cin >> v[next[curr]] >> next[next[curr]];

			curr = next[curr];
			ans = v[curr];
		}
	}

	cout << "! " << ans << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, start, x, i, j, k, curr, maxx = -1, maxid = -1, ans;
	cin >> n >> start >> x;

	vector<int> v(n + 1, -1), next(n + 1, -1);

	curr = start;
	for (i = 0; i < n; i++) {
		while (v[curr] != -1) curr = ((rand() * 1000 + rand()) % n) + 1;
		cout << "? " <<  curr << "\n";
		cout.flush();

		cin >> v[curr] >> next[curr];
		if ((v[curr] > maxx) && (v[curr] <= x)) {
			maxx = v[curr];
			maxid = curr;
		}
	}

	curr = maxid;
	while (v[curr] < x) {
		if (next[curr] == -1) {
			ans = -1;
			break;
		}
		cout << "? " << next[curr] << "\n";
		cout.flush();
		cin >> v[next[curr]] >> next[next[curr]];

		curr = next[curr];
		ans = v[curr];
	}

	cout << "! " << ans << "\n";

	return 0;
}


n=int(input())
a=list(map(str,input().split()))
b=list(map(str,input().split()))
s=set()
main=0
for i in range(n):
	s.add(i+1)
for i in range(n):
	test=b[i:]+b[:i]
	# print(test)
	b1="".join(test)
	a1="".join(a)
	# print(a1)
	# print(b1)
	# print(s)
	ans=0
	rem=[]
	for j in s:
		# print(a1[j-1],b1[j-1])
		if(a1[j-1]==b1[j-1]):
			ans+=1
			rem.append(j)
	for j in (rem):
		s.remove(j)

	if(ans>main):
		main=ans
	if(ans>n//2):
		break
print(main)


n=int(input())
a=list(map(int,input().split()))
a1=[0]*n
inda=a.index(1)
af=a[inda:]+a[:inda]
b=list(map(int,input().split()))
indb=b.index(1)
b1=[0]*n
bf=b[indb:]+b[:indb]
# print(af)
# print(bf)
for i in range(n):
	a1[af[i]-1]=i
for i in range(n):
	b1[bf[i]-1]=i
ans=0
for i in range(n):
	if(af[i]==bf[i]):
		ans+=1
# print(a)
# print(a1)
# print(b)
# print(b1)
print(ans)


n=int(input())
a=list(map(int,input().split()))
a1=[0]*n
inda=a.index(1)
af=a[inda:]+a[:inda]
b=list(map(int,input().split()))
indb=b.index(1)
b1=[0]*n
bf=b[indb:]+b[:indb]
# print(af)
# print(bf)
for i in range(n):
	a1[af[i]-1]=i
for i in range(n):
	b1[bf[i]-1]=i
ans=0
for i in range(n):
	if(af[i]==bf[i]):
		ans+=1
l=[0]*n
for i in range(n):
	l[i]=a1[i]-b1[i]
ans=[0]*n
for i in l:
	ans[i]+=1

# print(a)
# print(a1)
# print(b)
# print(b1)
print(max(ans))


x = int(input())
for _ in range(x):
    I1 = [item for item in map(int,input().split())]
    I2 = [item for item in map(int,input().split())]
    sign1=[0]*x
    for i in range(x):
        for j in range(x):
            if I1[j] - 1 == i:
                sign1[i] += j
            if I2[j] - 1 == i:
                sign1[i] -= j
    final=[0]*x
    for k in range(x):
        final[(sign1[k])%x]+=1
    print(max(final))


x = int(input())
for _ in range(x):
    I1 = [item for item in map(int,input().split())]
    I2 = [item for item in map(int,input().split())]
    sign1=[0]*x
    for i in range(x):
        for j in range(x):
            if I1[j] - 1 == i:
                sign1[i] += j
            if I2[j] - 1 == i:
                sign1[i] -= j
    final=[0]*x
    for k in range(x):
        final[(sign1[k])%x]+=1
print(max(final))


x = int(input())
I1 = [item for item in map(int,input().split())]
I2 = [item for item in map(int,input().split())]
sign1=[0]*x
for j in range(x):
    sign1[I1[j] - 1] += j
    sign1[I2[j] - 1 ] -= j
final=[0]*x
for k in range(x):
    final[(sign1[k])%x]+=1
print(max(final))


x = int(input())
I1 = [item for item in map(int,input().split())]
I2 = [item for item in map(int,input().split())]
sign1=[0]*x
for i in range(x):
    for j in range(x):
        if I1[j] - 1 == i:
            sign1[i] += j
        if I2[j] - 1 == i:
            sign1[i] -= j
final=[0]*x
for k in range(x):
    final[(sign1[k])%x]+=1
print(max(final))


x = int(input())
for _ in range(x):
    I1 = [item for item in map(int,input().split())]
    I2 = [item for item in map(int,input().split())]
    sign1=[0]*x
    sign2=[0]*x
    for i in range(x):
        for j in range(x):
            if I1[j] - 1 == i:
                sign1[i] = j
            if I2[j] - 1 == i:
                sign2[i] = j
    final=[0]*x
    for k in range(x):
        final[(sign1[k]-sign2[k])%x]+=1
    print(max(final))


from sys import stdin, stdout
cin = stdin.readline
cout  = stdout.write
mp = lambda: list(map(int, cin().split()))

n, = mp()
a = mp()
b = mp()

pos = [0]*(n+1)
ans = [0]*n

for i in range(n):
	pos[b[i]] = i
	#ans += a[i] == b[i]

k = 0
for i in range(n):
	ans[(pos[a[i]]-i)%n] += 1
cout(str(sorted(ans, reverse=True)[0]))


from sys import stdin, stdout
cin = stdin.readline
cout  = stdout.write
mp = lambda: list(map(int, cin().split()))

n, = mp()
a = mp()
b = mp()

pos = [0]*(n+1)
ans = [0]*n

for i in range(n):
	pos[b[i]] = i
	#ans += a[i] == b[i]

k = 0
for i in range(n):
	ans[(pos[a[i]]-i)%n] += 1
cout(str(max(ans)))


from collections import defaultdict as dd
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
m = dict()
x=dict()
for i in range(n):
    m[a[i]]=i
for i in range(n):
    x[b[i]]=i
c=dd(lambda:0)
for i in range(1,n+1):
    c[((m[i]-x[i]+n)%n)]+=1
print(max(c.values()))


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
m = dict()
x=dict()
for i in range(n):
    m[a[i]]=i
for i in range(n):
    x[b[i]]=i
c,d=[],[]
for i in range(1,n+1):
    c.append(m[i])
for i in range(1,n+1):
    d.append(x[i])
e,f,g=0,0,0
for i in range(n):
    if c[i]-d[i] == 1 or d[i]-c[i]==n-1:
        e+=1
for i in range(n):
    if d[i]-c[i] == 1 or c[i]-d[i]==n-1:
        f+=1
for i in range(n):
    if c[i]-d[i] == 0:
        g+=1
print(max(e,f,g))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]
D=[]
E=[]
if len(A)<=1:
    print (1)
else:

    for i in range (1, n+1):
        a=A.index(i)
        b=B.index(i)
        C.append((a-b)%n)
        if (a-b)%n not in E:
            E.append((a-b)%n)

    for i in E:
        t=C.count(i)
        D.append(t)

    print (max(D))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]
D=[]
if len(A)<=1:
    print (1)
else:

    for i in range (1, n+1):
        a=A.index(i)
        b=B.index(i)
        C.append((a-b)%n)

    for i in C:
        t=C.count(i)
        D.append(t)

    print (max(D))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]
D=[]
E=[]
if len(A)<=1:
    print (1)
else:

    for i in range (0, n):
        b=B.index(A[i])
        C.append((i-b)%n)
        if (i-b)%n not in E:
            E.append((i-b)%n)

    for i in E:
        t=C.count(i)
        D.append(t)

    print (max(D))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]
if len(A)<=1:
    print (1)
else:

    for i in range (0, len(A)):
        a,b=A[0],A[1]
        for j in range (0, len(A)):
            A[(j+1)%(len(A))]=a
            a,b = b,A[(j+2)%(len(A))]
        x=0
        for j in range (0,len(A)):

            if A[j]==B[j]:
                x+=1
        C.append(x)
    print (max(C))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]
if len(A)<=1:
    print (0)
else:

    for i in range (0, len(A)):
        a,b=A[0],A[1]
        for j in range (0, len(A)):
            A[(j+1)%(len(A))]=a
            a,b = b,A[(j+2)%(len(A))]
        x=0
        for j in range (0,len(A)):

            if A[j]==B[j]:
                x+=1
        C.append(x)
    print (max(C))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[0 for x in range (0,n)]
D=C.copy()
E=C.copy()
E.append(0)
X=[]

if len(A)<=1:
    print (1)
else:
    for i in range (0,n):
        C[A[i]-1]=i
        D[B[i]-1]=i
    for i in range (0,n):
        e=(C[i]-D[i])%n
        E[e]=E[e]+1

    print (max(E))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[0 for x in range (0,n)]
D=C.copy()
X=[]
E=[]
if len(A)<=1:
    print (1)
else:
    for i in range (0,n):
        C[A[i]-1]=i
        D[B[i]-1]=i
    for i in range (0,n):
        e=(C[i]-D[i])%n
        E.append(e)

    for i in E:
        t=E.count(i)
        X.append(t)

    print (max(X))


n=int(input())
A=[int(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[]

for i in range (0, len(A)):
    a,b=A[0],A[1]
    for j in range (0, len(A)):
        A[(j+1)%(len(A))]=a
        a,b = b,A[(j+2)%(len(A))]
    x=0
    for j in range (0,len(A)):

        if A[j]==B[j]:
            x+=1
    C.append(x)
print (max(C))


arr_size = int(input())

dict_a = dict()
for i, a in enumerate(list(map(int, input().split())), start=1):
    dict_a[a] = i

dict_b = dict()
for i, b in enumerate(list(map(int, input().split())), start=1):
    key = (i - dict_a[b]) % arr_size
    if key in dict_b:
        dict_b[key] += 1
    else:
        dict_b[key] = 1

result = max(dict_b.values())
print(result)


def cyclicalShiftRight(array, magnitude):
    magnitude = magnitude % len(array)
    array[0:magnitude], array[magnitude:] = array[-magnitude:], array[0:-magnitude]

def similarity(a, b):
    count = 0
    for ind in range(len(a)):
        if a[ind] == b[ind]:
            count += 1
    return count

arr_size = int(input())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))

if arr_a == reversed(arr_b):
    if arr_size % 2 == 0:
        print(2)
    else:
        print(1)
    exit(0)

similarity_count = similarity(arr_a, arr_b)

for i in range(arr_size):
    if similarity_count == arr_size:
        break
    cyclicalShiftRight(arr_b, 1)
    print(arr_b)
    new_count = similarity(arr_a, arr_b)
    if new_count > similarity_count:
        similarity_count = new_count

print(similarity_count)


def cyclicalShiftRight(array, magnitude):
    magnitude = magnitude % len(array)
    array[0:magnitude], array[magnitude:] = array[-magnitude:], array[0:-magnitude]

def similarity(a, b):
    count = 0
    for ind in range(len(a)):
        if a[ind] == b[ind]:
            count += 1
    return count

arr_size = int(input())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))

if arr_a == list(reversed(arr_b)):
    if arr_size % 2 == 0:
        print(2)
    else:
        print(1)
    exit(0)

similarity_count = similarity(arr_a, arr_b)

for i in range(arr_size):
    if similarity_count == arr_size:
        break
    cyclicalShiftRight(arr_b, 1)
    print(arr_b)
    new_count = similarity(arr_a, arr_b)
    if new_count > similarity_count:
        similarity_count = new_count


def cyclicalShiftRight(array):
    array[0], array[1:] = array[-1], array[0:-1]

def similarity(a, b):
    count = 0
    for ind in range(len(a)):
        if a[ind] == b[ind]:
            count += 1
    return count

arr_size = int(input())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))

similarity_count = similarity(arr_a, arr_b)

for i in range(arr_size):
    if similarity_count == arr_size:
        break
    cyclicalShiftRight(arr_b)
    new_count = similarity(arr_a, arr_b)
    if new_count > similarity_count:
        similarity_count = new_count

print(similarity_count)


def cyclicalShiftRight(array, magnitude):
    magnitude = magnitude % len(array)
    array[0:magnitude], array[magnitude:] = array[-magnitude:], array[0:-magnitude]

def similarity(a, b):
    count = 0
    for ind in range(len(a)):
        if a[ind] == b[ind]:
            count += 1
    return count

arr_size = int(input())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))

if arr_a == list(reversed(arr_b)):
    if arr_size % 2 == 0:
        print(2)
    else:
        print(1)
    exit(0)

similarity_count = similarity(arr_a, arr_b)

for i in range(arr_size):
    if similarity_count == arr_size:
        break
    cyclicalShiftRight(arr_b, 1)
    new_count = similarity(arr_a, arr_b)
    if new_count > similarity_count:
        similarity_count = new_count

print(similarity_count)


n = int(input())
a = input().split()
b = input().split()
max_sp = 0
for i in range(n):
    sp = 0
    for j in range(n):
        if a[j - i] == b[j]:
            sp += 1
    max_sp = max(max_sp, sp)
print(max_sp)


n = int(input())
a = input()
sp = {}
sp_a = []
ln = 0
for i in enumerate(a.split()):
    sp_a.append(i)
    ln += 1
sp_a.sort(key=lambda x: x[1])
b = input()
sp_b = []
for i in enumerate(b.split()):
    sp_b.append(i)
sp_b.sort(key=lambda x: x[1])
for i in range(ln):
    if sp_a[i][0] < sp_b[i][0]:
        dif = sp_a[i][0] + ln
        sp_a[i] = (dif, sp_a[i][1])
    num = sp.get(sp_a[i][0] - sp_b[i][0], 0)
    sp[sp_a[i][0] - sp_b[i][0]] = num + 1
print(max(sp.values()))


def solve(n, a, b):
    ixs = [None] * (n)
    for i, v in enumerate(a):
        ixs[v - 1] = i
    shifts = [0] * n
    for i, v in enumerate(b):
        base = i - ixs[v - 1]
        if base < 0:
            base += n
        shifts[base] += 1
    return max(shifts)

n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
print(solve(n, a, b))


def solve(n, a, b):
    ixs = [None] * (n)
    for i, v in enumerate(a):
        ixs[v - 1] = i
    shifts = [0] * (n - 1)
    for i, v in enumerate(b):
        base = i - ixs[v - 1]
        if base < 0:
            base += n
        shifts[base - 1] += 1
    return max(shifts)

n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
print(solve(n, a, b))


n = int(input())
a = input()
sp = {}
sp_a = []
ln = 0
for i in enumerate(a.split()):
    sp_a.append(i)
    ln += 1
sp_a.sort(key=lambda x: x[1])
b = input()
sp_b = []
for i in enumerate(b.split()):
    sp_b.append(i)
sp_b.sort(key=lambda x: x[1])
for i in range(ln):
    if sp_a[i][0] < sp_b[i][0]:
        dif = sp_a[i][0] + ln
        sp_a[i] = (dif, sp_a[i][1])
    num = sp.get(sp_a[i][0] - sp_b[i][0], 0)
    sp[sp_a[i][0] - sp_b[i][0]] = num + 1
print(sp)
print(max(sp.values()))


n = int(input())
a = input()
sp = {}
sp_a = []
ln = 0
for i in enumerate(a[::2]):
    sp_a.append(i)
    ln += 1
sp_a.sort(key=lambda x: x[1])
b = input()
sp_b = []
for i in enumerate(b[::2]):
    sp_b.append(i)
sp_b.sort(key=lambda x: x[1])
for i in range(ln):
    if sp_a[i][0] < sp_b[i][0]:
        dif = sp_a[i][0] + ln
        sp_a[i] = (dif, sp_a[i][1])
    num = sp.get(sp_a[i][0] - sp_b[i][0], 0)
    sp[sp_a[i][0] - sp_b[i][0]] = num + 1
print(max(sp.values()))


n=int(input())
a=[int(v) for v in input().split()]
b=[int(v) for v in input().split()]
d=dict()
res=[]
for j in range(n):
    d[b[j]]=j
for j in range(n):
    if d[a[j]]<j:
        res.append(d[a[j]]+n-j)
    else:
        res.append(d[a[j]]-j)
m=1
d={}
for j in range(n):
    if res[j] in d:
        d[res[j]]=d[res[j]]+1
        m=max(m,d[res[j]])
    else:
        d[res[j]]=1
print(m)


n=int(input())
a=[int(v) for v in input().split()]
b=[int(v) for v in input().split()]
d=dict()
res=[]
for j in range(n):
    d[b[j]]=j
for j in range(n):
    if d[a[j]]<j:
        res.append(d[a[j]]+n-j)
    else:
        res.append(d[a[j]]-j)
v=n-len(set(res))+1
print(v)


from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pos = [0 for x in range(n+1)]

mmax = 0
offset = [0 for x in range(n+1)]
for i in range(n):
    pos[a[i]]=i
for i in range(n):

    cur = pos[b[i]] - i
    if cur  <0:
        cur += n
    offset[cur]+=1

ans = 0
for i in offset:
    ans = max(ans,i)
print(ans)


from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

mmax = 0

for i in range(len(a)):

    count = 0
    for i in range(len(a)):
        if b[i] == a[i]:
            count +=1
    mmax = max(mmax,count)
    b = deque(b)
    b.rotate(1)
    b = list(b)
print(mmax)


n = int(input())
a = [0] * (n + 1)
for i, x in enumerate(map(int, input().split())):
    a[x] = i
b = [0] * (n + 1)
for i, x in enumerate(map(int, input().split())):
    y = ((i - a[x]) % n + n) % n
    b[y] += 1
print(max(b))


n = int(input())
a, b = {}, {}
for i, x in enumerate(map(int, input().split())):
    y = ((x - i) % n + n) % n
    a[y] = a.get(y, 0) + 1
for i, x in enumerate(map(int, input().split())):
    y = ((x - i) % n + n) % n
    b[y] = b.get(y, 0) + 1
print(min(max(a.values()), max(b.values())))


n = int(input())
a, b = {}, {}
for i, x in enumerate(map(int, input().split())):
    y = (x - i) % n
    a[y] = a.get(y, 0) + 1
for i, x in enumerate(map(int, input().split())):
    y = (x - i) % n
    b[y] = b.get(y, 0) + 1
print(min(max(a.values()), max(b.values())))


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# from math import sqrt, floor, factorial, gcd, log
# from collections import deque, Counter, defaultdict
# from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solve():
    n = int(input()); arr = read(); arr2 = read()
    i1 = arr.index(1); i2 = arr2.index(1)
    c = 0
    for i in range(n):
        if arr[(i1+i)%n] == arr2[(i2+i)%n]:
            c += 1
    print(c)

if __name__ == "__main__":
	solve()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
# from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solve():
    n = int(input()); a = read(); b = read()
    a1, b1 = [0]*n, [0]*n
    c = defaultdict(int)
    for i in range(n):
        if a[i] < i+1:
            a1[i] = (n - abs((i+1)-a[i]))
        elif a[i] >= i+1:
            a1[i] = a[i]-(i+1)

        if b[i] < i+1:
            b1[i] = (n - abs((i+1)-b[i]))
        elif b[i] >= i+1:
            b1[i] = b[i] - (i+1)
        c[a1[i]+b1[i]] += 1
    # print(a1)
    # print(b1)
    # print(c)

    print(max(c.values()))

if __name__ == "__main__":
	solve()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
# from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solve():
    n = int(input()); a = read(); b = read()
    c = defaultdict(int)
    for i in range(n):
        if a[i] < i+1:
            a[i] = (n - abs((i+1)-a[i]))
        elif a[i] >= i+1:
            a[i] -= (i+1)

        if b[i] < i+1:
            b[i] = (n - abs((i+1)-b[i]))
        elif b[i] >= i+1:
            b[i] -= (i+1)
        c[a[i]+b[i]] += 1
    # print(a)
    # print(b)
    # print(c)

    print(max(c.values()))

if __name__ == "__main__":
	solve()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
# from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solve():
    n = int(input()); a = read(); b = read()
    dic = {a[i]:i for i in range(n)}
    c = defaultdict(int)
    for i in range(n):
        if i <= dic[b[i]]:
            c[dic[b[i]]- i] += 1
        else:
            c[n - abs(dic[b[i]] - i)] += 1
    print(max(c.values()))

if __name__ == "__main__":
	solve()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
# from bisect import bisect

input = lambda: sys.stdin.readline().rstrip("\r\n")
read = lambda: list(map(int, input().strip().split(" ")))

def solve():
    n = int(input()); a = read(); b = read()
    c = defaultdict(int)
    for i in range(n):
        if a[i] < i+1:
            a[i] = (n - (i+1)+a[i])
        elif a[i] >= i+1:
            a[i] -= (i+1)

        if b[i] < i+1:
            b[i] = (n - (i+1)+b[i])
        elif b[i] >= i+1:
            b[i] -= (i+1)
        c[a[i]+b[i]] += 1

    print(max(c.values()))

if __name__ == "__main__":
	solve()


import sys
import math

n = int(sys.stdin.readline().strip())
a = list(map(int,sys.stdin.readline().strip().split(' ')))
b = list(map(int,sys.stdin.readline().strip().split(' ')))

i = 0
cnt = 0
while i < len(b) and b[i] != a[0]:
    i += 1

if i == len(b):
    print(0)
else:
    for j in range(n):
        if b[(i+j)%n] == a[j]:
            cnt += 1
print(cnt)


import sys
import math
import collections

n = int(sys.stdin.readline().strip())
a = list(map(int,sys.stdin.readline().strip().split(' ')))
b = list(map(int,sys.stdin.readline().strip().split(' ')))

aa = {}
bb = {}
for i in range(n):
    aa[a[i]] = i+1
    bb[b[i]] = i+1

res = collections.defaultdict(int)
for i in range(1, n+1):
    distanceRight = bb[i] - aa[i]
    distanceLeft = distanceRight
    if distanceRight < 0:
        distanceLeft = distanceRight % n
    else:
        distanceLeft -= n
    res[distanceRight] += 1
    res[distanceLeft] += 1

print(max(res.values()))


import sys
import math

n = int(sys.stdin.readline().strip())
a = list(map(int,sys.stdin.readline().strip().split(' ')))
b = list(map(int,sys.stdin.readline().strip().split(' ')))

def solve(a, b, index):
    i = 0
    cnt = 0
    while i < len(b) and b[i] != a[index]:
        i += 1

    for j in range(n):
        if b[(i+j)%n] == a[(index+j)%n]:
            cnt += 1
    return cnt

res = 1
for i in range(n):
    res = max(res, solve(a, b, i))
print(res)


for i in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    d1={}
    d2={}
    l=[0]*n
    for i in a:
        d1[i]=i
    for i in b:
        d2[i]=i
    for i in a:
        k=d1[i]-d2[i]
        if k<0:
            k+=n
        l[k]+=1
    print(max(l))


n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
d1={}
d2={}
l=[0]*n
for i in a:
    d1[i]=i
for i in b:
    d2[i]=i
for i in a:
    k=d1[i]-d2[i]
    if k<0:
        k+=n
    l[k]+=1
print(max(l))


n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
d1={}
d2={}
l=[0]*n
for i in range(n):
    d1[a[i]]=i
for i in range(n):
    d2[b[i]]=i
for i in a:
    k=d1[i]-d2[i]
    if k<0:
        k+=n
    l[k]+=1
#print(d1,d2)
#print(l)
print(max(l))


n=int(input())
l=list(map(int,input().split(" ")))
m=list(map(int,input().split(" ")))
dic={}
for x in range(n):
    t=m.index(l[x])
    if (t-x)%n not in dic.keys():
        dic[(t-x)%n]=1
    else:
        dic[(t-x)%n]=dic[(t-x)%n]+1
print(max(dic.values()))


n=int(input())
l=list(map(int,input().split(" ")))
m=list(map(int,input().split(" ")))
dic={}
tt={}
for x in range(n):
    tt[m[x]]=x
for x in range(n):
    t=tt[m[x]]
    if (t-x)%n not in dic.keys():
        dic[(t-x)%n]=1
    else:
        dic[(t-x)%n]=dic[(t-x)%n]+1
print(max(dic.values()))


n=int(input())
l=list(map(int,input().split(" ")))
m=list(map(int,input().split(" ")))
dic={}
tt={}
for x in range(n):
    tt[m[x]]=x
for x in range(n):
    t=tt[l[x]]
    if (t-x)%n not in dic.keys():
        dic[(t-x)%n]=1
    else:
        dic[(t-x)%n]=dic[(t-x)%n]+1
print(max(dic.values()))


n=int(input())
l=list(map(int,input().split(" ")))
m=list(map(int,input().split(" ")))
s=0
ans=[]
for _ in range(n):
    count=0
    for x in range(n):
        if l[x]==m[x]:
            count=count+1
    ans.append(count)
    temp=l[0]
    for y in range(n-1):
        l[y]=l[y+1]
    l[n-1]=temp
print(max(ans))


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=0
j=0
count=0
if(a[0] in b):
    d=b.index(a[i])
b=b[d:]+b[:d]

print(a,b)
for i in range(n):
    if(a[i]==b[i]):
        count+=1
print(count)


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    s[a[i]-1]=i
d=dict()
for i in range(n):
    t=s[b[i]-1]-i
    if(t<0):
        t+=n
    if t in d:
        d[t]+=1
    else:
        d[t]=1
print(max(d.values()))


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=0
j=0
count=0
if(a[0] in b):
    d=b.index(a[i])
b=b[d:]+b[:d]

for i in range(n):
    if(a[i]==b[i]):
        count+=1
print(count)


from collections import Counter

def tc():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_rot = [0] * n
    b_rot = [0] * n
    for i, v in enumerate(a):
        a_rot[v - 1] = i
    for i, v in enumerate(b):
        b_rot[v - 1] = i

    print(a_rot)
    print(b_rot)

    diffs = []
    for i in range(n):
        diff = a_rot[i] - b_rot[i]
        if diff < 0: diff += n
        diffs.append(diff)
    c = Counter(diffs)
    return max(c.values())

##################################
# T = int(input())
T = 1
for _ in range(T):
    ans = tc()
    print(ans)


from collections import Counter

def tc():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_rot = [0] * n
    b_rot = [0] * n
    for i, v in enumerate(a):
        a_rot[v - 1] = i
    for i, v in enumerate(b):
        b_rot[v - 1] = i

    diffs = []
    for i in range(n):
        diff = a_rot[i] - b_rot[i]
        if diff < 0: diff += n
        diffs.append(diff)
    c = Counter(diffs)
    return max(c.values())

##################################
# T = int(input())
T = 1
for _ in range(T):
    ans = tc()
    print(ans)


from collections import Counter

def tc():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    a += a
    b += b
    a_from1 = [0] * n
    b_from1 = [0] * n

    offset = 0
    while a[offset] != 1:
        offset += 1
    for i in range(n):
        val = a[(i + offset) % n]
        a_from1[val - 1] = i

    offset = 0
    while b[offset] != 1:
        offset += 1
    for i in range(n):
        val = b[(i + offset) % n]
        b_from1[val - 1] = i

    diffs = Counter([x - y for x, y in zip(a_from1, b_from1)])
    ans = diffs.most_common(1)[0][1]
    return ans

##################################
# T = int(input())
T = 1
for _ in range(T):
    ans = tc()
    print(ans)


import math

def tc():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    a += a
    b += b
    a_from1 = [0] * n
    b_from1 = [0] * n

    offset = 0
    while a[offset] != 1:
        offset += 1
    for i in range(n):
        val = a[(i + offset) % n]
        a_from1[val - 1] = i

    offset = 0
    while b[offset] != 1:
        offset += 1
    for i in range(n):
        val = b[(i + offset) % n]
        b_from1[val - 1] = i

    ans = 0
    for x, y in zip(a_from1, b_from1):
        if x == y:
            ans += 1

    return ans

##################################
# T = int(input())
T = 1
for _ in range(T):
    ans = tc()
    print(ans)


N=int(input())
ai=list(map(int,input().split()))
bi=list(map(int,input().split()))
if N<3:
    print(N)
else:
    final={}
    lst={}
    for i in range(N):
        final[bi[i]]=i
    for i in range(N):
        if final[ai[i]]-i==-N+1:
            final[ai[i]]=1
        elif final[ai[i]]-i==N-1:
            final[ai[i]]=-1
        else:
            final[ai[i]]-=i

    for i in final:
        if final[i] not in lst:
            lst[final[i]]=1
        else:
            lst[final[i]]+=1
    high=1
    for i in lst:
        if lst[i]>high:
            high=lst[i]
    print(high)


N=int(input())
ai=list(map(int,input().split()))
bi=list(map(int,input().split()))
final={}
lst={}
for i in range(N):
    if bi[i] not in final:
        final[bi[i]]=i
    else:
        if final[bi[i]]+i==-N+1:
            final[bi[i]]=1
        elif final[bi[i]]+i==N-1:
            final[bi[i]]=-1
        else:
            final[bi[i]]+=i
    if ai[i] not in final:
        final[ai[i]]=-i
    else:
        if final[ai[i]]-i==-N+1:
            final[ai[i]]=1
        elif final[ai[i]]-i==N-1:
            final[ai[i]]=-1
        else:
            final[ai[i]]-=i

for i in final:
    if final[i] not in lst:
        lst[final[i]]=1
    else:
        lst[final[i]]+=1
high=1
for i in lst:
    if lst[i]>high:
        high=lst[i]
print(high)


def val(ai,bi):
    final={}
    lst={}
    for i in range(N):
        final[bi[i]]=i
    for i in range(N):
        if final[ai[i]]-i<0:
            final[ai[i]]=N-i+final[ai[i]]
        else:
            final[ai[i]]-=i

    for i in final:
        if final[i] not in lst:
            lst[final[i]]=1
        else:
            lst[final[i]]+=1
    high=1
    for i in lst:
        if lst[i]>high:
            high=lst[i]
    return high
N=int(input())
ai=list(map(int,input().split()))
bi=list(map(int,input().split()))
if N<3:
    print(N)
else:
    print(val(ai,bi))


N=int(input())
ai=list(map(int,input().split()))
bi=list(map(int,input().split()))
final={}
lst=[]
count=0
for i in ai:
    temp=bi.index(i)
    if temp-count==(-N+1):
        lst.append(1)
    elif temp-count==N-1:
        lst.append(-1)
    else:
        lst.append(temp-count)
    count+=1
high=1
val=0
for i in lst:
    if i!=val:
        temp=lst.count(i)
        val=i
    if high<temp:
        high=temp
print(high)


# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 12:04:29 2020

@author: Dark Soul
"""
from collections import Counter

def Most_Common(lst):
    data = Counter(lst)
    return data.most_common(1)[0][0]

n=int(input(''))
act=list(map(int, input().split()))
cpy=list(map(int, input().split()))
act=list(map(lambda act:act-1, act))
cpy=list(map(lambda cpy:cpy-1, cpy))
act1=act.copy()
cpy1=cpy.copy()

for i in range(n):
    cpy[cpy1[i]]=i
    act[act1[i]]=i

diff=[]
for i in range(n):
    k=act[i]-cpy[i]+n

    diff.append(k%n)

maxx=Most_Common(diff)
print(diff.count(maxx))


# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 12:04:29 2020

@author: Dark Soul
"""
from collections import Counter

def Most_Common(lst):
    data = Counter(lst)
    return data.most_common(1)[0][0]

n=int(input(''))
act=list(map(int, input().split()))
cpy=list(map(int, input().split()))
act=list(map(lambda act:act-1, act))
cpy=list(map(lambda cpy:cpy-1, cpy))
act1=act.copy()
cpy1=cpy.copy()

for i in range(n):
    cpy[cpy1[i]]=i
    act[act1[i]]=i

diff=[]
for i in range(n):
    k=act[i]-cpy[i]
    if -k>=n-1:
        k=n-abs(k)
    diff.append(k)

maxx=Most_Common(diff)
print(diff.count(maxx))


from collections import Counter
def solve(n, a, b):
    for i in range(n):
        a[i] -=1
        b[i] -=1
    c = [0 for i in range(n)]
    d = [0 for i in range(n)]
    for i in range(n):
        c[a[i]] = i
    m = 0
    for i in range(n):
        d[i] = (c[b[i]] - i + n) % n
    g = Counter(d)
    m = 0
    for i in g.items():
        if m < i[1]:
            m = i[1]
    return m

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


def solve(n, a, b):
    y = 0
    k = 0
    m = 0
    while y < n:
        p = 0
        for i in range(n):
            if a[(i+y)%n] == b[i]:
                p += 1
        # print(p)
        if m < p:
            k = y
            m = p
        y += 1
    return m

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


def solve(n, a, b):
    s = set()
    for i in range(n):
        s.add(i)
    y = 0
    m = 0
    while y < n:
        k = 0
        h = s.copy()
        for i in s:
            if a[(i+y)%n] == b[i]:
                h.remove(i)
                k += 1
        if m < k:
            m = k
        s = h.copy()
        if len(s) == 0:
            break
        y += 1
    return m

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b))


for _ in range(int(input())):
    s=input()
    x=10000000000000

    for i in range(len(s)+1):
        x=min(x,s[:i].count('0')+s[i:].count('1'))
        x=min(x,s[:i].count('1')+s[i:].count('0'))

    print(x)


n=int(input())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
arr=list(zip(arr,range(0,n)))
arr.sort()
brr=list(zip(brr,range(0,n)))
brr.sort()
cnt=[0]*n
for i in range(n):
	cnt[(arr[i][1]-brr[i][1])%n]+=1
print(max(cnt))


from collections import Counter
n = int(input())
pos_as = {k: v for k, v in zip(map(int, input().split()), range(0, n))}
j = []
for pos_b, v in enumerate(map(int, input().split())):
    k = pos_b - pos_as[v]
    j.append(k if k >=0 else n+k)
print(max(Counter(j).values()))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = [b[i-1] for i in a]
print(max(Counter(map(lambda x: x[1] - x[0]-1, enumerate(a))).values()))


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = [b[i-1] for i in a]
a = list(range(b[0], n+1)) + list(range(1, b[0]))
print(len(list(filter(lambda x: x[0]==x[1], zip(a, b)))))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b = [b[i-1] for i in a]
print(max(Counter(map(lambda x: x[1] - x[0]+1, enumerate(a))).values()))