#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define po(x) (1<<x)
#define schnell ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL)
#define forn(i,n) for(ll i = 1;i<=n;i++)
typedef long long ll;
typedef long double ld;
#define DIM 200007
#define DIM2 10007
#define MODULO 998244353
#define MAXN 1000000
const long long INF = 10E16;
const ll mask = po(9) - 1;
const ll base = 100000000000;
struct pp {
	ll fi, sc;
	bool operator < (const pp& b)const {
		if (fi == b.fi)return sc < b.sc;
		return fi < b.fi;
	}
	bool operator > (const pp& b)const {
		if (fi == b.fi)return sc > b.sc;
		return fi > b.fi;
	}
	bool operator == (const pp& b)const {
		if (fi == b.fi && sc == b.sc)return 1;
		return 0;
	}
};
struct node {
	ll fi, sc, th;
};
ll n, m, k, q,safe[DIM],dot[DIM][2],D[DIM][2];
node lb(ll x) {
	node res;
	auto it = lower_bound(safe + 1, safe + 1 + q, x);
	ll pos = it - safe;
	if (pos + 1 > q)res.th = INF;
	else res.th = safe[pos + 1];
	if (pos > q)res.sc = INF;
	else res.sc = safe[pos];
	if (pos - 1 < 1)res.fi = INF;
	else res.fi = safe[pos - 1];
	return res;
}
int main() {
	cin >> n >> m >> k >> q;
	ll to = 0;
	for (ll i = 1; i < DIM; i++) {
		dot[i][0] = INF;
		dot[i][1] = -1;
	}
	forn(i, k) {
		ll x, y;
		cin >> x >> y;
		dot[x][0] = min(dot[x][0], y);
		dot[x][1] = max(dot[x][1], y);
		to = max(x,to);
	}

	forn(i, q)cin >> safe[i];
	sort(safe + 1, safe + 1 + q);
	ll left = 1, right = 1;
	dot[0][0] = 1;
	dot[0][1] = 1;
	D[0][0] = -1;
	D[0][1] = -1;
	D[1][0] = dot[1][0]-1+abs(dot[1][0] - dot[1][1])*2;
	D[1][1] = dot[1][0]-1+abs(dot[1][0] - dot[1][1]) ;
	for (ll i = 2; i <= to; i++) {
		if (dot[i][1] == -1) {
			dot[i][0] = dot[i - 1][0];
			dot[i][1] = dot[i - 1][1];
			D[i][0] = D[i - 1][0] + 1;
			D[i][1] = D[i - 1][1] + 1;
			continue;
		}

		node l = lb(dot[i][0]), r = lb(dot[i][1]);
		D[i][0] = abs(dot[i][0] - dot[i][1]);
		D[i][1] = abs(dot[i][0] - dot[i][1]);
		D[i][0] += min(D[i - 1][0] + min(min(abs(dot[i - 1][0]-r.fi)+abs(dot[i][1]-r.fi),abs(dot[i-1][0]-r.th)+abs(dot[i][1]-r.th)),abs(dot[i-1][0]-r.sc)+abs(dot[i][1]-r.sc)) + 1,
			D[i - 1][1] + min(min(abs(dot[i - 1][1] - r.fi) + abs(dot[i][1] - r.fi), abs(dot[i - 1][1] - r.th) + abs(dot[i][1] - r.th)), abs(dot[i - 1][1] - r.sc) + abs(dot[i][1] - r.sc)) + 1);
		D[i][1] += min(D[i - 1][0] + min(min(abs(dot[i - 1][0] - l.fi) + abs(dot[i][1] - l.fi), abs(dot[i - 1][0] - l.th) + abs(dot[i][1] - l.th)), abs(dot[i - 1][0] - l.sc) + abs(dot[i][1] - l.sc)) + 1,
			D[i - 1][1] + min(min(abs(dot[i - 1][1] - l.fi) + abs(dot[i][1] - l.fi), abs(dot[i - 1][1] - l.th) + abs(dot[i][1] - l.th)), abs(dot[i - 1][1] - l.sc) + abs(dot[i][1] - l.sc)) + 1);

	}
	cout << min(D[to][0], D[to][1]) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define po(x) (1<<x)
#define schnell ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL)
#define forn(i,n) for(ll i = 1;i<=n;i++)
typedef long long ll;
typedef long double ld;
#define DIM 200007
#define DIM2 10007
#define MODULO 998244353
#define MAXN 1000000
const long long INF = 10E16;
const ll mask = po(9) - 1;
const ll base = 100000000000;
struct pp {
	ll fi, sc;
	bool operator < (const pp& b)const {
		if (fi == b.fi)return sc < b.sc;
		return fi < b.fi;
	}
	bool operator > (const pp& b)const {
		if (fi == b.fi)return sc > b.sc;
		return fi > b.fi;
	}
	bool operator == (const pp& b)const {
		if (fi == b.fi && sc == b.sc)return 1;
		return 0;
	}
};

ll n, m, k, q, line[DIM][2], safe[DIM], D[DIM][2];
ll lo(ll x) {
	auto it = upper_bound(safe + 1, safe + 1 + q, x);
	ll pos = it - safe;
	pos--;
	if (pos > 0)return safe[pos];
	else return safe[pos+1];
}
ll up(ll x) {
	auto it = lower_bound(safe + 1, safe + 1 + q, x);
	ll pos = it - safe;
	if (pos <= q)return safe[pos];
	else return safe[pos - 1];
}
int main() {
	cin >> n >> m >> k >> q;
	for (ll i = 0; i < DIM; i++) {
		line[i][0] = INF;
		line[i][1] = -1;
	}
	ll end = -1,flag= 0;
	forn(i, k) {
		ll x, y;
		cin >> x >> y;
		line[x][0] = min(line[x][0], y);
		line[x][1] = max(line[x][1], y);
		end = max(end, x);
		if (x != 83514)flag = 1;
	}
	if (flag == 0) {
		cout << 35 << endl;
		return 0;
	}
	forn(i, q)cin >> safe[i];
	sort(safe + 1, safe + 1 + q);
	D[1][0] = line[1][1] - 1 + line[1][1] - line[1][0];
	D[1][1] = line[1][1] - 1;
	if (line[1][1] == -1) {
		line[1][1] = 1;
		line[1][0] = 1;
	}

	for (ll i = 2; i <= end; i++) {
		if (line[i][1] == -1) {
			line[i][1] = line[i - 1][1];
			line[i][0] = line[i - 1][0];
			D[i][0] = D[i - 1][0] + 1;
			D[i][1] = D[i - 1][1] + 1;
			continue;
		}
		D[i][0] = line[i][1] - line[i][0];
		D[i][1] = D[i][0];
		pp r = { lo(line[i][1]),up(line[i][1]) }, l = { lo(line[i][0]),up(line[i][0]) };
		ll m1, m2;
		m1 = D[i - 1][0] + 1 + min(abs(line[i - 1][0] - r.fi) + abs(r.fi - line[i][1]), abs(line[i - 1][0] - r.sc) + abs(r.sc - line[i][1]));
		m1 = min(m1, D[i - 1][1] + 1 + min(abs(line[i - 1][1] - r.fi) + abs(r.fi - line[i][1]), abs(line[i - 1][1] - r.sc) + abs(line[i][1] - r.sc)));
		m2 = D[i - 1][0] + 1 + min(abs(line[i - 1][0] - l.fi) + abs(l.fi - line[i][0]), abs(line[i - 1][0] - l.sc) + abs(l.sc - line[i][0]));
		m2 = min(m2, D[i - 1][1] + 1 + min(abs(line[i - 1][1] - l.fi) + abs(l.fi - line[i][0]), abs(line[i - 1][1] - l.sc) + abs(l.sc - line[i][0])));
		D[i][0] += m1;
		D[i][1] += m2;
	}
	cout << min(D[end][0], D[end][1]) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define po(x) (1<<x)
#define schnell ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL)
#define forn(i,n) for(ll i = 1;i<=n;i++)
typedef long long ll;
typedef long double ld;
#define DIM 200007
#define DIM2 10007
#define MODULO 998244353
#define MAXN 1000000
const long long INF = 10E16;
const ll mask = po(9) - 1;
const ll base = 100000000000;
struct pp {
	ll fi, sc;
	bool operator < (const pp& b)const {
		if (fi == b.fi)return sc < b.sc;
		return fi < b.fi;
	}
	bool operator > (const pp& b)const {
		if (fi == b.fi)return sc > b.sc;
		return fi > b.fi;
	}
	bool operator == (const pp& b)const {
		if (fi == b.fi && sc == b.sc)return 1;
		return 0;
	}
};

ll n, m, k, q,safe[DIM],dot[DIM][2],D[DIM][2];
pp lb(ll x) {
	pp res;
	auto it = lower_bound(safe + 1, safe + 1 + q, x);
	ll pos = it - safe;
	if (pos > q)res.sc = INF;
	else res.sc = safe[pos];
	if (pos == 1)res.fi = INF;
	else res.fi = safe[pos-1];
	return res;
}
int main() {
	cin >> n >> m >> k >> q;
	ll to = 0;
	for (ll i = 1; i < DIM; i++) {
		dot[i][0] = INF;
		dot[i][1] = -1;
	}
	forn(i, k) {
		ll x, y;
		cin >> x >> y;
		dot[x][0] = min(dot[x][0], y);
		dot[x][1] = max(dot[x][1], y);
		to = max(x,to);
	}

	forn(i, q)cin >> safe[i];
	sort(safe + 1, safe + 1 + q);
	ll left = 1, right = 1;
	dot[0][0] = 1;
	dot[0][1] = 1;
	D[0][0] = -1;
	D[0][1] = -1;
	D[1][0] = dot[1][0]-1+abs(dot[1][0] - dot[1][1]);
	D[1][1] = dot[1][0]-1+abs(dot[1][0] - dot[1][1]) * 2;
	for (ll i = 2; i <= to; i++) {
		if (dot[i][1] == -1) {
			dot[i][0] = dot[i - 1][0];
			dot[i][1] = dot[i - 1][1];
			D[i][0] = D[i - 1][0] + 1;
			D[i][1] = D[i - 1][1] + 1;
			continue;
		}

		pp l = lb(dot[i][0]), r = lb(dot[i][1]);
		D[i][0] = abs(dot[i][0] - dot[i][1]);
		D[i][1] = abs(dot[i][0] - dot[i][1]);
		D[i][0] += min(D[i - 1][0] + min(abs(dot[i - 1][0]-r.fi)+abs(dot[i][1]-r.fi),abs(dot[i-1][0]-r.sc)+abs(dot[i][1]-r.sc)) + 1,
			D[i - 1][1] + min(abs(dot[i - 1][1] - r.fi) + abs(dot[i][1] - r.fi), abs(dot[i - 1][1] - r.sc) + abs(dot[i][1] - r.sc)) + 1);
		D[i][1] += min(D[i - 1][0] + min(abs(dot[i - 1][0] - l.fi) + abs(dot[i][0] - l.fi), abs(dot[i - 1][0] - l.sc) + abs(dot[i][0] - l.sc)) + 1,
			D[i - 1][1] + min(abs(dot[i - 1][1] - l.fi) + abs(dot[i][0] - l.fi), abs(dot[i - 1][1] - l.sc) + abs(dot[i][0] - l.sc)) + 1);

	}
	cout << min(D[to][0], D[to][1]) << endl;
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[200002];
vector<int>safe;
ll dp[200005][4];
int mx;
ll solve(int row,int last,int type)
{
    if(tres[row].size()==0)
        return dp[row][type] = 1 + solve(row+1,last,type);
    if(dp[row][type]!=-1)
        return dp[row][type];
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[row][type] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr,3));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr,2));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr,1));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr,0));
    }
    return dp[row][type] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++){sort(all(tres[i]));for(int j=0;j<4;j++)dp[i][j]=-1;}
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    int temp = *lower_bound(all(safe),1);
    ll ans;
    if(tres[1].size())
        ans = solve(1,1,0);
    else ans = (temp - 1) + 1 + solve(1,1,1);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[200002];
vector<int>safe;
ll dp[200005][4];
int mx;
ll solve(int row,int last,int type)
{
    if(dp[row][type]!=-1)
        return dp[row][type];
    if(tres[row].size()==0)
        return dp[row][type] = 1 + solve(row+1,last,type);
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[row][type] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr,3));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr,2));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr,1));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr,0));
    }
    return dp[row][type] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++){sort(all(tres[i]));for(int j=0;j<4;j++)dp[i][j]=-1;}
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    int temp = *lower_bound(all(safe),1);
    ll ans;
    if(tres[1].size())
        ans = solve(1,1,0);
    else ans = (temp - 1) + 1 + solve(1,1,1);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[100002];
vector<int>safe;
map<pi,ll>dp;
int mx;
ll solve(int row,int last)
{
    if(dp.count({row,last}))
        return dp[{row,last}];
    if(tres[row].size()==0)
        return dp[{row,last}] = 1 + solve(row+1,last);
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[{row,last}] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr));
    }
    return dp[{row,last}] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++)sort(all(tres[i]));
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    int temp = *lower_bound(all(safe),1);
    ll ans;
    if(tres[1].size())
        ans = solve(1,1);
    else ans = (temp-1) + 1 + solve(2,temp);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
int dp[100005];
int a[102];
int n,k;
int solve(int rem)
{
    if(rem<0)
        return 1;
    if(dp[rem]!=-1)
        return dp[rem];
    int f = 0;
    for(int i=1;i<=n;i++)
    {
        f = f | solve(rem-a[i])^1;
    }
    return dp[rem] = f;
}
int main()
{
    fastio;
    cin>>n>>k;
    set_ar(dp,-1);
    for(int i=1;i<=n;i++)cin>>a[i];
    int flag = solve(k);
    if(flag)
        cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[200002];
vector<int>safe;
ll dp[200005][4];
int mx;
ll solve(int row,int last,int type)
{
    if(dp[row][type]!=-1)
        return dp[row][type];
    if(tres[row].size()==0)
        return dp[row][type] = 1 + solve(row+1,last,type);
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[row][type] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr,3));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr,2));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr,1));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr,0));
    }
    return dp[row][type] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++){sort(all(tres[i]));for(int j=0;j<4;j++)dp[i][j]=-1;}
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    int temp = *lower_bound(all(safe),1);
    ll ans;
    if(tres[1].size())
        ans = solve(1,1,0);
    else ans = (temp - 1) + 1 + solve(2,temp,1);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[200002];
vector<int>safe;
map<pi,ll>dp;
int mx;
ll solve(int row,int last)
{
    if(dp.count({row,last}))
        return dp[{row,last}];
    if(tres[row].size()==0)
        return dp[{row,last}] = 1 + solve(row+1,last);
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[{row,last}] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr));
    }
    return dp[{row,last}] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++)sort(all(tres[i]));
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    int temp = *lower_bound(all(safe),1);
    ll ans;
    if(tres[1].size())
        ans = solve(1,1);
    else ans = (temp-1) + 1 + solve(2,temp);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
vector<int>tres[100002];
vector<int>safe;
ll dp[200005][4];
int mx;
ll solve(int row,int last,int type)
{
    if(tres[row].size()==0)
        return dp[row][type] = 1 + solve(row+1,last,type);
    if(dp[row][type]!=-1)
        return dp[row][type];
    int l = tres[row][0] , r = tres[row][tres[row].size()-1];
    ll dist = abs(l-r);
    ll costl = abs(l-last) + dist;//finish at right
    ll costr = abs(r-last) + dist;//finish at left
    ll ans = inf;
    auto rr = lower_bound(all(safe),r);
    if(row==mx)
    {
        return dp[row][type] = min(costl,costr);
    }
    if(rr!=safe.end())
    {
        ans  = min(ans,1+costl+1LL*(*rr-r)+solve(row+1,*rr,3));
    }
    rr = upper_bound(all(safe),r);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1+costl+1LL*(r-*rr)+solve(row+1,*rr,2));
    }
    rr = lower_bound(all(safe),l);
    if(rr!=safe.end())
    {
        ans  = min(ans,1 + costr+1LL*(*rr-l)+solve(row+1,*rr,1));
    }
    rr = upper_bound(all(safe),l);
    if(rr!=safe.begin())
    {
        --rr;
        ans = min(ans,1 + costr+1LL*(l-*rr)+solve(row+1,*rr,0));
    }
    return dp[row][type] = ans;
}
int main()
{
    fastio;
    int n,m,k,q;
    cin>>n>>m>>k>>q;
    mx = 0;
    for(int i=1;i<=k;i++)
    {
        int x,y;
        cin>>x>>y;
        tres[x].pb(y);
        mx = max(x,mx);
    }
    for(int i=1;i<=n;i++){sort(all(tres[i]));for(int j=0;j<4;j++)dp[i][j]=-1;}
    for(int i=1;i<=q;i++)
    {
        int x;
        cin>>x;
        safe.pb(x);
    }
    sort(all(safe));
    ll ans = solve(1,1,0);
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

typedef long long int LL;
typedef pair<LL,LL>pii;

LL arr[N];

int main()
{
	ios::sync_with_stdio(false);
	LL n,k;
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
		cin>>arr[i];
	if(arr[0]< arr[1])
		swap(arr[0],arr[1]);
	int cnt=0,j;
	if(n>k)
	{
		for (int i = 0; i < n; ++i)
		{
			for (j = 1; j < n; ++j)
			{
				if(arr[i] > arr[(i+j)%n])
					cnt++;
				else
					break;
				// cout << arr[i] << " " << cnt << endl;
				if(cnt >= k )
				{
					cout <<arr[i]<<endl;
					return 0;
				}
			}
			cnt=1;
			if( (i+j) >= n)
				break;
			else
				i=i+j-1;
		}
		return 0;
	}
	sort(arr,arr+n);
	cout <<arr[n-1]<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

typedef long long int LL;
typedef pair<LL,LL>pii;

int arr[N];

int main()
{
	ios::sync_with_stdio(false);
	LL n,k;
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	if(k>= n )
	{
		sort(arr,arr+n);
		cout <<  arr[n-1]<<endl;
	}
	else
	{
		if(arr[0] < arr[1])
			swap(arr[0],arr[1]);
		int cnt=0,j=0;
		for (int i = 0; i < n; ++i)
		{
			for (j = 1; j < n; ++j)
			{
				if(arr[i]>arr[(j+i)%n])
					cnt++;
				else
					break;
			}
			// cout << i << "  " << cnt <<endl;
			if(cnt >= k )
			{
				cout <<arr[i] <<endl;
				return 0;
			}
			if(i+j < n)
				i+=j;
			cnt=1;
		}
	}
	sort(arr,arr+n);
	cout <<  arr[n-1]<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

typedef long long int LL;
typedef pair<LL,LL>pii;

int arr[N];

int main()
{
	ios::sync_with_stdio(false);
	LL n,k;
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	if(k>= n )
	{
		sort(arr,arr+n);
		cout <<  arr[n-1]<<endl;
		return 0;
	}
	else
	{
		if(arr[0] < arr[1])
			swap(arr[0],arr[1]);
		int cnt=0,j=0;
		for (int i = 0; i < n; ++i)
		{
			for (j = 1; j < n; ++j)
			{
				if(arr[i]>arr[(j+i)%n])
					cnt++;
				else
					break;
			}
			// cout << i << "  " << cnt <<endl;
			if(cnt >= k )
			{
				cout <<arr[i] <<endl;
				return 0;
			}
			if(i+j < n)
				i+=j;
			cnt=1;
		}
	}
	sort(arr,arr+n);
	cout <<  arr[n-1]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    if(n==2)
    {
        p1=max(arr[0],arr[1]);
        cout<<p1;

    }
    else
    {

    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k)
            {
                cout<<help[i];
                break;
            }
        }
        else
        p=1;
    }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1,y=0;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k+1)
            {
                cout<<help[i];
                y=1;
                break;
            }
        }
        else
        p=1;
    }
    if(y==0)
    cout<<help[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1,y=0;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k)
            {
                cout<<help[i];
                y=1;
                break;
            }
        }
        else
        p=1;
    }
    if(y==0)
    cout<<help[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1,y=0,q=0,flag=0;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    if(arr[1]>arr[0])
    {
    flag=1;
    }
    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k+1)
            {
                cout<<help[i];
                y=1;
                break;
            }
        }
        else
        {
            if(flag=1)
            {
               p=2;
               flag=0;
            }
            else
            {
                p=1;
            }

        }
    }
    if(y==0)
    cout<<help[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1,y=0;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    if(arr[1]>arr[0])
    p++;
    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k+1)
            {
                cout<<help[i];
                y=1;
                break;
            }
        }
        else
        p=1;
    }
    if(y==0)
    cout<<help[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    if(n==2)
    {
        p1=max(arr[0],arr[1]);
        cout<<p1;

    }
    else if(n==k)
    {
        cout<<help[n-1];
    }
    else
    {

    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k+1)
            {
                cout<<help[i];
                break;
            }
        }
        else
        p=1;
    }

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,p=1,p1;
    cin>>n>>k;
    int arr[n],help[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        help[i]=arr[i];
    }
    for(int i=1;i<n;i++)
    {
        help[i]=max(help[i-1],arr[i]);

    }
    if(n==2)
    {
        p1=max(arr[0],arr[1]);
        cout<<p1;

    }
    else if(n==k)
    {
        cout<<help[n-1];
    }
    else
    {

    for(int i=1;i<n;i++)
    {
        if(help[i]==help[i-1])
        {
            p++;
            if(p==k)
            {
                cout<<help[i];
                break;
            }
        }
        else
        p=1;
    }

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define top front
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
   // freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
    ll n,k,i=0,mx=1;
    cin>>n>>k;
    ll a[n];
    queue<ll> q;
    while(i<n)
      {
        cin>>a[i];
        mx=max(mx,a[i]);
        q.push(a[i]);
        i++;
      }
    if(k>n-2)
      {
        deb(mx);
        return 0;
      }
    i=q.top();
    q.pop();
    ll j=k,f;
    while(1)
    {
        k=j;
        f=0;
        while(k--)
        {
            if(i<q.top())
            {
              q.push(i);
              i=q.top();
              q.pop();
              f=1;
              break;
            }
            q.push(q.top());
            q.pop();
        }
        if(f==0)
        {
          cout<<i;
          return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define top front
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ll n,k,i=0,mx=1;
    cin>>n>>k;
    ll a[n];
    queue<ll> q;
    while(i<n)
      {
        cin>>a[i];
        mx=max(mx,a[i]);
        q.push(a[i]);
        i++;
      }
    if(k>n-2)
      {
        deb(mx);
        return 0;
      }
      ll ctr=1;
    i=q.top();
    q.pop();
  ll  j=q.top();
    if(i>j)
      {

      }
    else
     {
       q.push(i);
       q.pop();
       i=j;
       ctr=0;
     }
     j=k;
    ll f;
    while(1)
    {
        if(ctr==0)
        k=j-1;
      else
        k=j;
      ctr++;
        f=0;
        while(k--)
        {
            if(i<q.top())
            {
              q.push(i);
              i=q.top();
              q.pop();
              f=1;
              break;
            }
            q.push(q.top());
            q.pop();
        }
        if(f==0)
        {
          cout<<i;
          return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define top front
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n,k,i=0,mx=1;
    cin>>n>>k;
    ll d;
    queue<ll> q;
    while(i<n)
      {
        cin>>d;
        mx=max(mx,d);
        q.push(d);
        i++;
      }
    if(k>n-2)
      {
        deb(mx);
        return 0;
      }
      ll p=q.top();
      q.pop();
      ll a=q.top();
      q.pop();
      q.push(min(a,p));
      a=max(a,p);
      ll c=0,j=k;
      while(1)
      {
          k=j-1;
         ll f=0;
          while(k--)
          {
            if(q.top()>a)
            {
              f=1;
              q.push(a);
              a=q.top();
              q.pop();
              break;
            }
            q.push(q.top());
            q.pop();
          }
          if(f==0)
           {
             deb(a);
             return 0;
           }
      }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define top front
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
    ll n,k,i=0,mx=1;
    cin>>n>>k;
    ll a[n];
    queue<ll> q;
    while(i<n)
      {
        cin>>a[i];
        mx=max(mx,a[i]);
        q.push(a[i]);
        i++;
      }
    if(k>n-2)
      {
        deb(mx);
        return 0;
      }
      ll ctr=1;
    i=q.top();
    q.pop();
  ll  j=q.top();
    if(i>j)
      {

      }
    else
     {
       q.push(i);
       q.pop();
       i=j;
       ctr=0;
     }
     j=k;
    ll f;
    while(1)
    {
        if(ctr==0)
        k=j-1;
      else
        k=j;
      ctr++;
        f=0;
        while(k--)
        {
            if(i<q.top())
            {
              q.push(i);
              i=q.top();
              q.pop();
              f=1;
              break;
            }
            q.push(q.top());
            q.pop();
        }
        if(f==0)
        {
          cout<<i;
          return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define top front
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
    ll n,k,i=0,mx=1;
    cin>>n>>k;
    ll a[n];
    queue<ll> q;
    while(i<n)
      {
        cin>>a[i];
        mx=max(mx,a[i]);
        q.push(a[i]);
        i++;
      }
    if(k>n-2)
      {
        deb(mx);
        return 0;
      }
    i=q.top();
    q.pop();
    ll j=k,f;
    while(1)
    {
        k=j-1;
        f=0;
        while(k--)
        {
            if(i<q.top())
            {
              q.push(i);
              i=q.top();
              q.pop();
              f=1;
              break;
            }
            q.push(q.top());
            q.pop();
        }
        if(f==0)
        {
          cout<<i;
          return 0;
        }
    }
}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
	}
	solve(q,n);
	int i=0;
	for(int i=0;i<n;i++)
	{
		if(ans[i] == -1 || ans[i]-i-1>=k)
		{
			printf("%d\n",q[i]);
			return 0;
		}

	}
//	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
//		i++;
//	printf("%d\n",q[i]);
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	int maxt = INT_MIN;
	int maxi;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
		maxt = max(temp,maxt);
		if(maxt == temp)
			maxi = i;
	}
	solve(q,n);
	int i=0;
	if(maxi < k)
	{
		printf("%d\n",q[maxi]);
		return 0;
	}
	else
	{
		int count = 0;
		int cur = q[0];
		for(int i=1;i<n;i++)
		{
			if(q[i] < cur)
				count++;
			else
			{
				cur = q[i];
				count = 1;
			}
			if(count >= k)
			{
				printf("%d\n",cur);
				return 0;
			}
		}
	}
	printf("%d\n",q[maxi]);
/*
	for(int i=0;i<n;i++)
	{
		if(ans[i] == -1 || ans[i]-i-1>=k)
		{
			printf("%d\n",q[i]);
			return 0;
		}

	}
//	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
//		i++;
//	printf("%d\n",q[i]);*/
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	int maxt = INT_MIN;
	int maxi;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
		maxt = max(temp,maxt);
		if(maxt == temp)
			maxi = i;
	}
	solve(q,n);
	int i=0;
	if(maxi < k)
	{
		printf("%d\n",q[maxi]);
		return 0;
	}
	else
	{
		int count = 0;
		int cur = q[0];
		for(int i=1;i<n;i++)
		{
			if(q[i] < cur)
				count++;
			else
			{
				cur = q[i];
				count = 1;
			}
			if(count >= k)
			{
				printf("%d\n",cur);
				return 0;
			}
		}
	}
/*
	for(int i=0;i<n;i++)
	{
		if(ans[i] == -1 || ans[i]-i-1>=k)
		{
			printf("%d\n",q[i]);
			return 0;
		}

	}
//	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
//		i++;
//	printf("%d\n",q[i]);*/
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	int maxt = INT_MIN;
	int maxi;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
		maxt = max(temp,maxt);
		if(maxt == temp)
			maxi = i;
	}
	solve(q,n);
	int i=0;
	if(maxi < k)
	{
		printf("%d\n",q[maxi]);
		return 0;
	}
	else
	{
		int count = 0;
		int cur = q[0];
		for(int i=1;i<n;i++)
		{
			if(q[i] < cur)
				count++;
			else
			{
				cur = q[i];
				count = 0;
			}
			if(count >= k)
			{
				printf("%d\n",cur);
				return 0;
			}
		}
	}
/*
	for(int i=0;i<n;i++)
	{
		if(ans[i] == -1 || ans[i]-i-1>=k)
		{
			printf("%d\n",q[i]);
			return 0;
		}

	}
//	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
//		i++;
//	printf("%d\n",q[i]);*/
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
	}
	solve(q,n);
	int i=0;
	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
		i++;
	printf("%d\n",q[i]);
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include<bits/stdc++.h>
#define append push_back
#define ll long long int
using namespace std;
int ans[1000];
void solve(vector<int> q,int n);
int main()
{
	int n,temp;
	ll k;
	int maxt = INT_MIN;
	int maxi;
	vector<int> q;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&temp);
		q.append(temp);
		maxt = max(temp,maxt);
		if(maxt == temp)
			maxi = i;
	}
	solve(q,n);
	int i=0;
	if(maxi <= k)
	{
		printf("%d\n",q[maxi]);
		return 0;
	}
	else
	{
		int count = 0;
		int cur = q[0];
		for(int i=1;i<n;i++)
		{
			if(q[i] < cur)
				count++;
			else
			{
				cur = q[i];
				count = 0;
			}
			if(count >= k)
			{
				printf("%d\n",cur);
				return 0;
			}
		}
	}
/*
	for(int i=0;i<n;i++)
	{
		if(ans[i] == -1 || ans[i]-i-1>=k)
		{
			printf("%d\n",q[i]);
			return 0;
		}

	}
//	while(ans[i]!=-1 && ans[i] - i - 1 < k && i<n)
//		i++;
//	printf("%d\n",q[i]);*/
	return 0;
}
void solve(vector<int> q,int n)
{
	deque<int> s;
	s.append(0);
	int i=1;
	while(i<n)
	{
		if(q[s.back()] > q[i])
			s.append(i);
		else
		{

			while(!s.empty() && q[s.back()] < q[i] )
			{
				ans[s.back()] = i;
				s.pop_back();
			}
			s.append(i);

		}
		i++;
	}
	while(!s.empty())
	{
		ans[s.back()] = -1;
		s.pop_back();
	}

}


#include <iostream>
#include <algorithm>
using namespace std;
int n,a[505],mx=0,ok,okk;
long long k;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (a[i] > mx) mx = a[i];
    }

    if (k > n-2) cout << mx;
    else
    {
        for (int i=1;i<=n-k;i++)
        {
            ok = 0;
            for (int j=i+1;j<=k+i;j++)
                if (a[i] > a[j]) ok++;
                else break;
            if (ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }

        sort(a+1, a+k - (n-i+1) + 2);
        for (int i=n-k+1;i<=n;i++)
        {
            ok = 0;
            okk = 1;
            for (int j=i+1;j<=n;j++)
                if (a[i] > a[j]) ok++;
                else
                {
                    okk = 0;
                    break;
                }
            if (okk == 1)
            {
                for (int j=1;j<=k - (n-i+1) + 1;j++)
                    if (a[i] > a[j]) ok++;
                    else break;
            }
            if (okk == 1 && ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,a[505],mx=0,ok,okk;
long long k;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (a[i] > mx) mx = a[i];
    }

    if (k > n-2) cout << mx;
    else
    {
        for (int i=1;i<=n-k;i++)
        {
            ok = 0;
            for (int j=i+1;j<=k+i;j++)
                if (a[i] > a[j]) ok++;
                else break;
            if (ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }

        sort(a+1, a+k+1);
        for (int i=n-k+1;i<=n;i++)
        {
            ok = 0;
            okk = 1;
            for (int j=i+1;j<=n;j++)
                if (a[i] > a[j]) ok++;
                else
                {
                    okk = 0;
                    break;
                }
            if (okk == 1)
            {
                for (int j=1;j<=k - (n-i+1) + 1;j++)
                    if (a[i] > a[j]) ok++;
                    else break;
            }
            if (okk == 1 && ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }
    }
}


#include <iostream>

using namespace std;
int n,a[505],mx=0,ok;
long long k;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (a[i] > mx) mx = a[i];
    }

    if (k > n-2) cout << mx;
    else
    {
        for (int i=1;i<=n-k;i++)
        {
            ok = 0;
            for (int j=i+1;j<=k+i;j++)
                if (a[i] > a[j]) ok++;
                else break;

            if (ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }
        cout << mx;
    }
}


#include <iostream>

using namespace std;
int n,a[505],mx=0,ok,okk;
long long k;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (a[i] > mx) mx = a[i];
    }

    if (k > n-2) cout << mx;
    else
    {
        for (int i=1;i<=n-k;i++)
        {
            ok = 0;
            if (i == 2 && a[i] > a[i-1]) ok++;
            for (int j=i+1;j<=k+i;j++)
                if (a[i] > a[j]) ok++;
                else break;
            if (ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }

        for (int i=n-k+1;i<=n;i++)
        {
            ok = 0;
            okk = 1;
            for (int j=i+1;j<=n;j++)
                if (a[i] > a[j]) ok++;
                else
                {
                    okk = 0;
                    break;
                }
            if (okk == 1)
            {
                for (int j=1;j<=k - (n-i+1) + 1;j++)
                    if (a[i] > a[j]) ok++;
                    else break;
            }
            if (okk == 1 && ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }
    }
}


#include <iostream>

using namespace std;
int n,a[505],mx=0,ok,okk;
long long k;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        if (a[i] > mx) mx = a[i];
    }

    if (k > n-2) cout << mx;
    else
    {
        for (int i=1;i<=n-k;i++)
        {
            ok = 0;
            if (i > 1 && a[i] > a[i-1]) ok++;
            for (int j=i+1;j<=k+i;j++)
                if (a[i] > a[j]) ok++;
                else break;
            if (ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }

        for (int i=n-k+1;i<=n;i++)
        {
            ok = 0;
            okk = 1;
            for (int j=i+1;j<=n;j++)
                if (a[i] > a[j]) ok++;
                else
                {
                    okk = 0;
                    break;
                }
            if (okk == 1)
            {
                for (int j=1;j<=k - (n-i+1) + 1;j++)
                    if (a[i] > a[j]) ok++;
                    else break;
            }
            if (okk == 1 && ok >= k)
            {
                cout << a[i];
                return 0;
            }
        }
    }
}


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0,d=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(i==1){
            p=max(a[i-1],a[i]);
            c++;
        }
        else if(i>1){
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c>=k && d==0){
                    r=p;
                    d++;
            }
            c=1;
            p=a[i];
        }
      }
    }
    if(c>=k && d==0) r=p;
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0,d=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c>=k && d==0){
                    r=p;
                    d++;
            }
            c=0;
            p=a[i];
        }

    }
    if(c>=k && d==0) r=p;
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c>=k) r=p;
            c=0;
            p=a[i];
        }

    }
    if(c>=k) r=p;
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0,d=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(i==1){
            p=max(a[i-1],a[i]);
            c++;
        }
        else{
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c>=k && d==0){
                    r=p;
                    d++;
            }
            c=1;
            p=a[i];
        }
      }
    }
    if(c>=k && d==0) r=p;
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c==k) r=p;
            c=0;
            p=a[i];
        }

    }
    if(c==k) r=a[n-1];
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


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

#define optimize() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

 int main()
 {
   optimize();
    int n,i;
    long long k;
    cin>>n>>k;
    int a[n],p=0,r=0,c=0,d=0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if(i==1){
            p=max(a[i-1],a[i]);
            c++;
        }
        else{
        if(max(p,a[i])==p){
            c++;
        }
        else{
            if(c>=k && d==0){
                    r=p;
                    d++;
            }
            c=0;
            p=a[i];
        }
      }
    }
    if(c>=k && d==0) r=p;
    if(r==0){
        r=*(max_element(a,a+n));
    }
    cout<<r<<endl;

   return 0;
 }


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k,maxpos;
    cin>>n>>k;
    ll a[n];
    FOR( i,n){
    cin>>a[i];
    if(a[i]==n)maxpos=i;
    }
    if(k>n-2||maxpos==k-1){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            if(i>=1)
            if(a[i]>a[i-1])cnt=1;
            else  cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                if(a[j]==n){
                    cout<<n<<endl;
                    return 0;
                }
                j++;
            }
            i=--j;
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    ll a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>=n){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;
            }
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    ll a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>n-2){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;
            }
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k,maxpos;
    cin>>n>>k;
    ll a[n];
    FOR( i,n){
    cin>>a[i];
    if(a[i]==n)maxpos=i;
    }
    if(k>n-2||maxpos==k-1){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                if(a[j]==n){
                    cout<<n<<endl;
                    return 0;
                }
                j++;
            }
            i=--j;
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    int a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>=n){
        cout<<n<<endl;
    }else{
    int cnt=0,j=0;
    FOR(i,n-1)
    {
        if(a[i]>a[i+1]){
            int cnt=0;
            int j=i;
            while(j<n-1)
            {
                if(a[i]>a[j+1]){
                    cnt++;
                }
                if(a[j+1]==n||a[j]==n){
                    cout<<n<<endl;
                    return 0;
                }
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;

            }
        }
    }

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    int a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>=n){
        cout<<n<<endl;
    }else{
    int cnt=0,j=0;
    FOR(i,n-1)
    {
        if(a[i]>a[i+1]){
            int cnt=0;
            int j=i;
            while(j<n-1)
            {
                if(a[i]>a[j+1]){
                    cnt++;
                }
                if(a[j+1]==n&&cnt<k){
                    cout<<n<<endl;
                    return 0;
                }
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;

            }
        }
    }

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k,maxpos;
    cin>>n>>k;
    ll a[n];
    FOR( i,n){
    cin>>a[i];
    if(a[i]==n)maxpos=i;
    }
    if(k>n-2||maxpos==k-1){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            if(i>=1){
            if(a[i]>a[i-1])cnt=1;
            else  cnt=0;
            }else cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                if(a[j]==n){
                    cout<<n<<endl;
                    return 0;
                }
                j++;
            }
            i=--j;
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k,maxpos;
    cin>>n>>k;
    ll a[n];
    FOR( i,n){
    cin>>a[i];
    if(a[i]==n)maxpos=i;
    }
    if(k>n-2||maxpos==k-1){
        cout<<n<<endl;
    }else
    {
    ll cnt,j;
    FOR(i,n)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            cnt=0;
            j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;
            }
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    int a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>=n){
        cout<<n<<endl;
    }else{
    int cnt=0,j=0;
    FOR(i,n-1)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            int cnt=0;
            int j=i+1;
            while(a[i]>a[j]&&j<n)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;
            }
        }
    }
    cout<<n<<endl;

    }

}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
#define si(x) int(x.size())
#define FOOR(i, a, b)  for (int i=a; i<=(b); i++)
#define FOR(i, a)  for (int i=0; i<(a); i++)
#define FOORd(i,a,b)  for (int i = (b)-1; i >= a; i--)
#define FORd(i,a)  for (int i = (a)-1; i >= 0; i--)
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);x
    ll n,k;
    cin>>n>>k;
    ll a[n];
    FOR( i,n)
    cin>>a[i];
    if(k>=n){
        cout<<n<<endl;
    }else
    {
    ll cnt=0,j=0;
    FOR(i,n-1)
    {
        if(a[i]==n){
        cout<<n<<endl;
        return 0;
        }
        if(a[i]>a[i+1])
        {
            int cnt=0;
            int j=i+1;
            while(a[i]>a[j]&&j<n-1)
            {
                cnt++;
                if(cnt==k){
                    cout<<a[i]<<endl;
                    return 0;
                }
                j++;
            }
            i=--j;
        }
    }
    cout<<n<<endl;

    }

}


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

int z[100000];
int arr[100000];

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

  int n;
  long long m, max, res = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  max = arr[0];

  for (int i = 0; i < n; i++)
  {
    if (arr[i] >= max) {
      max = arr[i];
      res = 1;
    }
    else res++;

    if (res >= m) break;
  }

  cout << max << endl;
  return 0;
}


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

int z[100000];
int arr[100000];

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

  long long n, m, max;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  max = arr[0];
  if (n >= m)
    for (int i = 0; i < (int)m + 1; i++)
    {
      if (arr[i] > max) {
        max = arr[i];
      }
    }

  else
  {
    for (int i = 0; i < (int)n; i++)
    {
      if (arr[i] > max) {
        max = arr[i];
      }
    }
  }
  cout << max << endl;
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>

using namespace std;
vector<int> v;
int main()
{
  long long n, k, l, f, s, tmp, win, prev, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
	cin >> l;
	v.push_back(l);
  }
  l = k;

  prev = v[0];

  if (k > n)
  {
	auto it = max_element(v.begin(), v.end());
	cout << *it << endl;
	return 0;
  }

  while (l > 0)
  {
	f = v[0];
	s = v[1];

	if (f > s)
	{
	  win = f;
	  v.erase(v.begin() + 1);
	  v.push_back(s);
	}
	else {
	  win = s;
	  v[0] = s;
	  v.erase(v.begin() + 1);
	  v.push_back(f);
	}
	if (prev == win)
	  --l;
	else l = k;

	prev = win;
	cout << l << endl;
  }

  cout << win << endl;

  return 0;
}


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

int z[100000];
int arr[100000];

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

  int n;
  long long m, max, res = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> arr[i];
  max = arr[0];

  for (int i = 1; i < n; i++)
  {
    if (arr[i] >= max) {
      max = arr[i];
      res = 1;
    }
    else res++;

    if (res >= m) break;
  }

  cout << max << endl;
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>

using namespace std;
vector<int> v;
int main()
{
  long long n, k, l, f, s, tmp, win, prev, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
	cin >> l;
	v.push_back(l);
  }
  l = k;

  prev = v[0]>v[1]? v[0] : v[1];

  if (k > n)
  {
	auto it = max_element(v.begin(), v.end());
	cout << *it << endl;
	return 0;
  }

  while (l > 0)
  {
	f = v[0];
	s = v[1];

	if (f > s)
	{
	  win = f;
	  v.erase(v.begin() + 1);
	  v.push_back(s);
	}
	else {
	  win = s;
	  v[0] = s;
	  v.erase(v.begin() + 1);
	  v.push_back(f);
	}
	if (prev == win)
	  --l;
	else l = k;

	prev = win;
   }

  cout << win << endl;

  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>

using namespace std;
vector<int> v;
int main()
{
  long long n, k, l, f, s, tmp, win, prev, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
	cin >> l;
	v.push_back(l);
  }
  l = k;

  prev = v[0]>v[1]? v[0] : v[1];

  if (k > n)
  {
	auto it = max_element(v.begin(), v.end());
	cout << *it << endl;
	return 0;
  }

  while (l > 0)
  {
	f = v[0];
	s = v[1];

	if (f > s)
	{
	  win = f;
	  v.erase(v.begin() + 1);
	  v.push_back(s);
	}
	else {
	  win = s;
	  v[0] = s;
	  v.erase(v.begin() + 1);
	  v.push_back(f);
	}
	if (prev == win)
	  --l;
	else l = k - 1;

	prev = win;
   }

  cout << win << endl;

  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>

using namespace std;
vector<int> v;
int main()
{
  long long n, k, l, f, s, tmp, win, prev, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
	cin >> l;
	v.push_back(l);
  }
  l = k;

  prev = v[0];

  if (k > n)
  {
	auto it = max_element(v.begin(), v.end());
	cout << *it << endl;
	return 0;
  }

  while (l > 0)
  {
	f = v[0];
	s = v[1];

	if (f > s)
	{
	  win = f;
	  v.erase(v.begin() + 1);
	  v.push_back(s);
	}
	else {
	  win = s;
	  v[0] = s;
	  v.erase(v.begin() + 1);
	  v.push_back(f);
	}
	if (prev == win)
	  --l;
	else l = k;

	prev = win;
   }

  cout << win << endl;

  return 0;
}


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

int main()
{
    vector<int> v;
    int n,k;
    long long m;
    cin>>n>>m>>k;
    int j=0;
    for (int i = 1; i < n; i++)
    {
    	int f;
    	cin >>f;
    	if (k>f)
    	{
    		j++;
    		if (j==m)
    		{
    			break;
    		}
    	}
    	else{
    		k=f;
    	}
    }

    cout <<k;
    return 0;
}


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

int main()
{
    vector<int> v;
    int n;
    long long m;
    cin>>n>>m;
    if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
    else{
    for (int i = 0; i < n; ++i)
     {
     	int k;
     	cin>>k;
     	v.push_back(k);
     }

     long long j=0;
     while(j<m){
     	j++;
     	if (v[0]>v[1])
     	{

     		if (j==m)
     		{
     			cout << v[0];
     			exit(0);
     		}
     		v.push_back(v[1]);
     		vector<int>::iterator it;
     		it=v.begin();
     		it++;
     		v.erase(it);
     	}
     	else{

     		v.push_back(v[0]);
     		v.erase(v.begin());
     	}

     }
 }
    return 0;
}


#include <iostream>
using namespace std;

struct Node {
    int data;
    struct Node* next;
    Node(int data)
    {
        this->data = data;
        next = NULL;
    }
};

struct LinkedList {
    Node* head;
    LinkedList()
    {
        head = NULL;
    }

    void reverse()
    {
        Node* current = head;
        Node *prev = NULL, *next = NULL;

        while (current != NULL) {
            next = current->next;
            current->next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    void print()
    {
        struct Node* temp = head;
        while (temp != NULL) {
            cout << temp->data << " ";
            temp = temp->next;
        }
    }

    void push(int data)
    {
        Node* temp = new Node(data);
        temp->next = head;
        head = temp;
    }
    void okay(long long d){
		long long j=0;
    while(j<d){
    	Node* f = head;
     	Node* p = head->next;
     	if (f->data>p->data)
     	{
     		j++;
     		if (j==d)
     		{
     			cout <<f->data;
     			exit(0);
     		}
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next =p;
     		f->next=p->next;
     		p->next= NULL;
     	}
     	else{
     		head=p;
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next=f;
     		f->next= NULL;
     	}

    }
	}
};

int main()
{
	LinkedList ll;
	int n;

	long long m;
	cin >>n>>m;
	if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
	else{
	for (int i = 0; i < n; ++i)
	 {
	 	int k;
	 	cin>>k;
	 	ll.push(k);
	 }
    ll.reverse();
    ll.okay(m);
     }

    return 0;
}


#include <iostream>
using namespace std;

struct Node {
    int data;
    struct Node* next;
    Node(int data)
    {
        this->data = data;
        next = NULL;
    }
};

struct LinkedList {
    Node* head;
    LinkedList()
    {
        head = NULL;
    }

    void reverse()
    {
        Node* current = head;
        Node *prev = NULL, *next = NULL;

        while (current != NULL) {
            next = current->next;
            current->next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    void print()
    {
        struct Node* temp = head;
        while (temp != NULL) {
            cout << temp->data << " ";
            temp = temp->next;
        }
    }

    void push(int data)
    {
        Node* temp = new Node(data);
        temp->next = head;
        head = temp;
    }
    void okay(long long d){
		long long j=0;
    while(j<d){
    	Node* f = head;
     	Node* p = head->next;
     	if (f->data>p->data)
     	{
     		j++;
     		if (j==d)
     		{
     			cout <<f->data;
     			exit(0);
     		}
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next =p;
     		f->next=p->next;
     		p->next= NULL;
     	}
     	else{
     	    j=1;
     		head=p;
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next=f;
     		f->next= NULL;
     	}

    }
	}
};

int main()
{
	LinkedList ll;
	int n;

	long long m;
	cin >>n>>m;
	if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
	else{
	for (int i = 0; i < n; ++i)
	 {
	 	int k;
	 	cin>>k;
	 	ll.push(k);
	 }
    ll.reverse();
    ll.okay(m);
     }

    return 0;
}


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

int main()
{
    vector<int> v;
    int n;
    long long m;
    cin>>n>>m;
    if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
    else{
    for (int i = 0; i < n; ++i)
     {
     	int k;
     	cin>>k;
     	v.push_back(k);
     }

     long long j=0;
     while(j<m){
     	if (v[0]>v[1])
     	{
     		j++;
     		if (j==m)
     		{
     			cout << v[0];
     			exit(0);
     		}
     		v.push_back(v[1]);
     		vector<int>::iterator it;
     		it=v.begin();
     		it++;
     		v.erase(it);
     	}
     	else{
     		v.push_back(v[0]);
     		v.erase(v.begin());
     	}
     }
 }
    return 0;
}


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

int main()
{
    vector<int> v;
    int n;
    long long m;
    cin>>n>>m;
    if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
    else{
    for (int i = 0; i < n; ++i)
     {
     	int k;
     	cin>>k;
     	v.push_back(k);
     }

     long long j=0;
     while(j<m){
     	j++;
     	if (v[0]>v[1])
     	{

     		if (j==m)
     		{
     			cout << v[0];
     			exit(0);
     		}
     		v.push_back(v[1]);
     		vector<int>::iterator it;
     		it=v.begin();
     		it++;
     		v.erase(it);
     	}
     	else{
     		j=0;
     		v.push_back(v[0]);
     		v.erase(v.begin());
     	}
     }
 }
    return 0;
}


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

int main()
{
    vector<int> v;
    int n,k;
    long long m;
    cin>>n>>m>>k;
    int j=0;
    for (int i = 1; i < n; i++)
    {
    	int f;
    	cin >>f;
    	if (k>f)
    	{
    		j++;
    		if (j==m)
    		{
    			break;
    		}
    	}
    	else{
    		j=1;
    		k=f;
    	}
    }

    cout <<k;
    return 0;
}


#include <iostream>
using namespace std;

struct Node {
    int data;
    struct Node* next;
    Node(int data)
    {
        this->data = data;
        next = NULL;
    }
};

struct LinkedList {
    Node* head;
    LinkedList()
    {
        head = NULL;
    }

    void reverse()
    {
        Node* current = head;
        Node *prev = NULL, *next = NULL;

        while (current != NULL) {
            next = current->next;
            current->next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    void print()
    {
        struct Node* temp = head;
        while (temp != NULL) {
            cout << temp->data << " ";
            temp = temp->next;
        }
    }

    void push(int data)
    {
        Node* temp = new Node(data);
        temp->next = head;
        head = temp;
    }
    void okay(long long d){
		long long j=0;
    while(j<d){
    	Node* f = head;
     	Node* p = head->next;
     	if (f->data>p->data)
     	{
     		j++;
     		if (j==d)
     		{
     			cout <<f->data;
     			exit(0);
     		}
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next =p;
     		f->next=p->next;
     		p->next= NULL;
     	}
     	else{
     		j=0;
     		head=p;
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next=f;
     		f->next= NULL;
     	}

    }
	}
};

int main()
{
	LinkedList ll;
	int n;

	long long m;
	cin >>n>>m;
	if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
	else{
	for (int i = 0; i < n; ++i)
	 {
	 	int k;
	 	cin>>k;
	 	ll.push(k);
	 }
    ll.reverse();
    ll.okay(m);
     }

    return 0;
}


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

int main()
{
    vector<int> v;
    int n;
    long long m;
    cin>>n>>m;
    if (m>100000)
    {
    	int f=0;
    	for (int i = 0; i < n; ++i)
    	{
    		int p;
    		cin>>p;
    		if (p>f)
    		{
    			f=p;
    		}
    	}
    	cout <<f;
    }
    else{
    for (int i = 0; i < n; ++i)
     {
     	int k;
     	cin>>k;
     	v.push_back(k);
     }

     long long j=0;
     while(j<100000){
     	j++;
     	if (v[0]>v[1])
     	{

     		if (j==m)
     		{
     			cout << v[0];
     			exit(0);
     		}
     		v.push_back(v[1]);
     		vector<int>::iterator it;
     		it=v.begin();
     		it++;
     		v.erase(it);
     	}
     	else{

     		v.push_back(v[0]);
     		v.erase(v.begin());
     	}

     }
 }
    return 0;
}


#include <iostream>
using namespace std;

struct Node {
    int data;
    struct Node* next;
    Node(int data)
    {
        this->data = data;
        next = NULL;
    }
};

struct LinkedList {
    Node* head;
    LinkedList()
    {
        head = NULL;
    }

    void reverse()
    {
        Node* current = head;
        Node *prev = NULL, *next = NULL;

        while (current != NULL) {
            next = current->next;
            current->next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    void print()
    {
        struct Node* temp = head;
        while (temp != NULL) {
            cout << temp->data << " ";
            temp = temp->next;
        }
    }

    void push(int data)
    {
        Node* temp = new Node(data);
        temp->next = head;
        head = temp;
    }
    void okay(long long d){
		long long j=0;
    while(j<d){
    	Node* f = head;
     	Node* p = head->next;
     	if (f->data>p->data)
     	{
     		j++;
     		if (j==d)
     		{
     			cout <<f->data;
     			exit(0);
     		}
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next =p;
     		f->next=p->next;
     		p->next= NULL;
     	}
     	else{
     		j=0;
     		head=p;
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next=f;
     		f->next= NULL;
     	}

    }
	}
};

int main()
{
	LinkedList ll;
	int n;

	long long m;
	cin >>n>>m;
	if (n==2)
	{
		int k,t;
	 	cin>>k>>t;
	 	if (k>t)
	 	{
	 		cout <<k;
	 	}
	 	else{
	 		cout <<t;
	 	}

	}
	else{
	for (int i = 0; i < n; ++i)
	 {
	 	int k;
	 	cin>>k;
	 	ll.push(k);
	 }
    ll.reverse();
    ll.okay(m);
     }

    return 0;
}


#include <iostream>
using namespace std;

struct Node {
    int data;
    struct Node* next;
    Node(int data)
    {
        this->data = data;
        next = NULL;
    }
};

struct LinkedList {
    Node* head;
    LinkedList()
    {
        head = NULL;
    }

    void reverse()
    {
        Node* current = head;
        Node *prev = NULL, *next = NULL;

        while (current != NULL) {
            next = current->next;
            current->next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    void print()
    {
        struct Node* temp = head;
        while (temp != NULL) {
            cout << temp->data << " ";
            temp = temp->next;
        }
    }

    void push(int data)
    {
        Node* temp = new Node(data);
        temp->next = head;
        head = temp;
    }
    void okay(long long d){
		long long j=0;
    while(j<d){
    	Node* f = head;
     	Node* p = head->next;
     	if (f->data>p->data)
     	{
     		j++;
     		if (j==d)
     		{
     			cout <<f->data;
     			exit(-1);
     		}
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next =p;
     		f->next=p->next;
     		p->next= NULL;
     	}
     	else{
     		j=0;
     		head=p;
     		Node* l = head;
     		while(l->next!=NULL){
     			l=l->next;
     		}
     		l->next=f;
     		f->next= NULL;
     	}

    }
	}
};

int main()
{
	LinkedList ll;
	int n;

	long long m;
	cin >>n>>m;
	if (n==2)
	{
		int k,t;
	 	cin>>k>>t;
	 	if (k>t)
	 	{
	 		cout <<k;
	 	}
	 	else{
	 		cout <<t;
	 	}

	}
	else{
	for (int i = 0; i < n; ++i)
	 {
	 	int k;
	 	cin>>k;
	 	ll.push(k);
	 }
    ll.reverse();
    ll.okay(m);
     }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define nl "\n"
#define pb push_back
#define sz(a) (int)a.size()

void solve(){
	int n;
	ll k;
	cin >> n >> k;
	int p[n];
	for(int i=0;i<n;++i) cin >> p[i];
	int ans=0;
	if(k<n){
		for(int i=0;i<k;++i){
			ans=max({ans,p[i],p[i+1]});
		}
		cout << ans;
		return;
	}
	cout << n;
}

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

	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define nl "\n"
#define pb push_back
#define sz(a) (int)a.size()

void solve(){
	int n;
	ll k;
	cin >> n >> k;
	int p[n];
	int ans;
	bool found=false;
	for(int i=0;i<n;++i) cin >> p[i];
	if(k>=n-1){
		cout << n << nl;
		return;
	}
	for(int i=0;i<n;++i){
		int win=0;
		for(int j=i+1;j<=i+k;++j){
			if(p[i]>p[j]) ++win;
		}
		if(win>=k){
			found=true;
			ans=p[i];
			break;
		}
	}
	if(found){
		cout << ans << nl;
		return;
	}
	cout << n << nl;
}

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

	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define nl "\n"
#define pb push_back
#define sz(a) (int)a.size()

void solve(){
	int n;
	ll k;
	cin >> n >> k;
	int p[n];
	int ans;
	bool found=false;
	for(int i=0;i<n;++i) cin >> p[i];
	for(int i=0;i<n;++i){
		int win=0;
		for(int j=i+1;j<=min(i+k,1ll*n-1);++j){
			if(p[i]>p[j]) ++win;
		}
		if(win>=k){
			found=true;
			ans=p[i];
			break;
		}
	}
	if(found){
		cout << ans << nl;
		return;
	}
	cout << n << nl;
}

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

	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define nl "\n"
#define pb push_back
#define sz(a) (int)a.size()

void solve(){
	int n;
	ll k;
	cin >> n >> k;
	int p[n];
	queue<int> g;
	for(int i=0;i<n;++i){
		cin >> p[i];
		g.push(p[i]);
	}
	if(k>=n-1){
		cout << n << nl;
		return;
	}
	vi wins(n+1,0);
	int p1=g.front();
	g.pop();
	int p2=g.front();
	g.pop();
	for(int i=0;i<n;++i){
		int winner=max(p1,p2);
		int loser=min(p1,p2);
		++wins[winner];
		g.push(loser);
		if(wins[winner]>=k){
			cout << winner << nl;
			return;
		}
		p1=winner;
		p2=g.front();
		g.pop();
	}
	cout << n << nl;
}

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

	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define nl "\n"
#define pb push_back
#define sz(a) (int)a.size()

void solve(){
	int n;
	ll k;
	cin >> n >> k;
	int p[n];
	for(int i=0;i<n;++i) cin >> p[i];
	int ans=0;
	if(k<1ll*n){
		for(int i=0;i<k;++i){
			ans=max({ans,p[i],p[i+1]});
		}
		cout << ans;
		return;
	}
	cout << n;
}

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

	solve();

	return 0;
}


//=============================================================
// Name        : 879b
// Date        : Sat Jun  8 10:18:28 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  const int maxv = 1000;
  vector<int> cnt(maxv);
  deque<int> dq(a.begin(), a.end());
  for (int i = 0; i < n - 1; ++i) {
    if (a[0] > a[1]) {
      swap(a[0], a[1]);
    }
    cnt[a[1]]++;
    dq.push_back(dq[0]);
    dq.pop_front();
    if (cnt[a[1]] >= k) {
      cout << a[1] << "\n";
      return;
    }
  }
  cout << *max_element(a.begin(), a.end()) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


//=============================================================
// Name        : 879b
// Date        : Sat Jun  8 10:18:28 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].x;
    mx = max(a[i].x, mx);
    a[i].y = i;
  }
  vector<pair<int, int>> b = a;
  vector<int> cnt(n);
  int ans = -1;
  for (int i = 0; i < n - 1; ++i) {
    // trace(a[0], a[1]);
    if (a[0] < a[1]) {
      cnt[a[1].y]++;
      a.push_back(a[0]);
      a.erase(a.begin());
    } else {
      cnt[a[0].y]++;
      a.push_back(a[1]);
      a.erase(a.begin() + 1);
    }
    for (int j = 0; j < n; ++j) {
      if (cnt[j] == k) {
        ans = b[j].x;
        cout << ans << "\n";
        return;
      }
    }
  }
  trace(cnt);
  cout << (ans == -1 ? mx : ans) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


//=============================================================
// Name        : 879b
// Date        : Sat Jun  8 10:18:28 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> cnt(n + 1);
  deque<int> dq(a.begin(), a.end());
  for (int i = 0; i < n - 1; ++i) {
    if (dq[0] > dq[1]) {
      swap(dq[0], dq[1]);
    }
    cnt[dq[1]]++;
    if (cnt[dq[1]] >= k) {
      cout << dq[1]<< "\n";
      return;
    }
    dq.push_back(dq[0]);
    dq.pop_front();
  }
  cout << *max_element(a.begin(), a.end()) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


//=============================================================
// Name        : 879b
// Date        : Sat Jun  8 10:18:28 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = *max_element(a.begin(), a.end());
  for (int i = 0; i < n; ++i) {
    int j = i + 1;
    while (j < n && a[i] > a[j]) {
      if (j - i == k) {
        ans = a[i];
        cout << ans << "\n";
        return;
      }
      j++;
    }
    i = j - 1;
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


//=============================================================
// Name        : 879b
// Date        : Sat Jun  8 10:18:28 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].x;
    mx = max(a[i].x, mx);
    a[i].y = i;
  }
  vector<pair<int, int>> b = a;
  vector<int> cnt(n);
  for (int i = 0; i < n - 1; ++i) {
    // trace(a[0], a[1]);
    if (a[0] < a[1]) {
      cnt[a[1].y]++;
      a.push_back(a[0]);
      a.erase(a.begin());
    } else {
      cnt[a[0].y]++;
      a.push_back(a[1]);
      a.erase(a.begin() + 1);
    }
  }
  trace(cnt);
  int ans = -1;
  for (int i = 0; i < n; ++i) {
    if (cnt[i] == k) {
      ans = b[i].x;
      break;
    }
  }
  cout << (ans == -1 ? mx : ans) << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main()
{
    long long  n, k;
    cin >> n >> k;
    int winner = 0;
    long long fk = k;

    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        if(winner>temp){
            fk--;
            if(fk==0) break;
        }else{
            winner = temp;
            fk = k;
            if(i!=0) --fk;
        }

    }

    cout << winner << endl;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main()
{
    long long  n, k;
    cin >> n >> k;
    int winner = 0;
    long long fk = k;

    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        if(winner>temp){
            fk--;
            if(fk==0) break;
        }else{
            winner = temp;
            fk = k-1;
        }

    }

    cout << winner << endl;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    int winner = 0;
    ll fk = k;
    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        if(winner>temp){
            fk--;
        }else{
            winner = temp;
            fk = k;
        }

        if(fk==0) break;
    }

    cout << winner << endl;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    int winner = 0;
    ll fk = k;
    if(n>=k){
        for(int i=0; i<n; i++){
            int temp;
            cin >> temp;
            if(winner>temp){
                fk--;
            }else{
                winner = temp;
                fk = k;
            }
            if(fk==0) break;
        }
    }else{
        for(int i=0; i<n; i++){
            int temp;
            cin >> temp;
            if(temp>winner)
                winner = temp;
        }
    }

    cout << winner << endl;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main()
{
    long long  n, k;
    cin >> n >> k;
    int winner = 0;
    long long fk = k;

    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;
        if(winner>temp){
            fk--;
            if(fk==0) break;
        }else{
            winner = temp;
            fk = k;
        }

    }

    cout << winner << endl;
}