#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvp = vector<vpl>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(),v.end()
vll mx;
ll k, fin=0;
vvl g;
void init(int n, int K) {
mx = vll(n,-1);k=K;
g = vvl(n);
}
void gof(ll i, ll v){
if(v<=mx[i])return;
if(v>=i)fin=1;
mx[i] = v;
for(ll j: g[i]){
gof(j, v);
}
}
int add_teleporter(int u, int v) {
g[u].pb(v);
if(u<k){
gof(v, u);
}
else gof(v, mx[u]);
return fin;
}