#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
int main()
{
    LL n,k; cin>>n>>k;
    vector<int>a;
    if(k>=n)return cout<<n , 0 ;
    for(int i=0;i<n;i++)
    {
        int x; cin>>x;
        a.pb(x);
    }
    int winner=a[0]; int num=0;
    a.erase(a.begin() + 0 );
    while(1)
    {
        if(winner>a.front()){num++; a.pb(a.front()); a.erase(a.begin()+0);}
        else {num=1; a.pb(winner); winner=a.front(); a.erase(a.begin()+0); }
        if(num>=k)return cout<<winner , 0 ;
    }
}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include <functional>

#define mod 1000000007
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.14159265359

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
int main()
{
    LL n,k; cin>>n>>k;
    vector<int>a;
    if(k>=n)return cout<<n , 0 ;
    for(int i=0;i<n;i++)
    {
        int x; cin>>x;
        a.pb(x);
    }
    int winner=a[0]; int num=0;
    a.erase(a.begin() + 0 );
    while(1)
    {
        if(winner>a.front()){num++; a.pb(a.front()); a.erase(a.begin()+0);}
        else {num=0; a.pb(winner); winner=a.front(); a.erase(a.begin()+0); }
        if(num>=k)return cout<<winner , 0 ;
    }
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
int main()
{
    int n ;
    ll k;
    int a[505];
    for(int i = 0; i < 5; i++){
        int aaa = 0;
    }
    while(~scanf("%d %I64d" , &n , &k)) {
        int maxn = 0;

        for(int i = 0 ; i < n ; i ++) {
            scanf("%d" , &a[i]);
            maxn = max(maxn , a[i]);
        }

        if(k >= n) {
            cout<<maxn<<endl;
        }
        else {
            int flag = 0 ;
            int mx = a[0];
            int num = 0 ;
            for(int i = 1 ; i < n ; i ++) {
                if(a[i] < mx) {
                    num ++;
                }
                else {
                    mx = a[i];
                    num = 0;
                }
                if(num == k) {
                    flag = 1 ;
                    break;
                }
            }
            if(flag == 1)
                cout<<mx<<endl;
            else
                cout<<maxn<<endl;
        }

    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int n ;
    ll k;
    int a[505];
    for(int i = 0; i < 5; i++){
        int aaa = 0;
    }
    while(~scanf("%d %I64d" , &n , &k)) {
        int maxn = 0;

        for(int i = 0 ; i < n ; i ++) {
            scanf("%d" , &a[i]);
            maxn = max(maxn , a[i]);
        }

        if(k >= n) {
            cout<<maxn<<endl;
        }
        else {
            int flag = 0 ;
            int mx = a[0];
            int num = 0 ;
            for(int i = 1 ; i < n ; i ++) {
                if(a[i] < mx) {
                    num ++;
                }
                else {
                    mx = a[i];
                    num = 1;
                }
                if(num == k) {
                    flag = 1 ;
                    break;
                }
            }
            if(flag == 1)
                cout<<mx<<endl;
            else
                cout<<maxn<<endl;
        }

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
//#include <limits>

using namespace std;

int main() {
	int n;
	long long plays;
	cin >> n >> plays;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		vec[i] = c;
	}
	if (plays >= n) {
		sort(vec.begin(), vec.end());
		cout << vec[n - 1] << endl;
		return 0;
	}
	else {
		int count = 0;
		int winner, winner_before = max(vec[0], vec[1]);
		while (count < plays) {
			if (vec[0] > vec[1]) {
				winner = vec[0];
				int loser = vec[1];
				vec.erase(vec.begin() + 1);
				vec.push_back(loser);

			}
			else {
				winner = vec[1];
				int loser = vec[0];
				vec.erase(vec.begin());
				vec.push_back(loser);
			}
			if (winner_before == winner) count++;
			else count = 0;
		}
		cout << winner << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
//#include <limits>

using namespace std;

int main() {
	int n;
	long long plays;
	cin >> n >> plays;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		vec[i] = c;
	}
	if (plays >= n) {
		sort(vec.begin(), vec.end());
		cout << vec[n - 1] << endl;
		return 0;
	}
	else {
		int count = 0;
		int winner, winner_before = max(vec[0], vec[1]);
		while (count < plays) {
			if (vec[0] > vec[1]) {
				winner = vec[0];
				int loser = vec[1];
				vec.erase(vec.begin() + 1);
				vec.push_back(loser);
				count++;

			}
			else {
				winner = vec[1];
				int loser = vec[0];
				vec.erase(vec.begin());
				vec.push_back(loser);
				count++;
			}
			if (winner_before != winner) {
				winner_before = winner;
				count = 1;
			}
		}
		cout << winner << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(){
short t,x,mx=0,mi=0;long long k;
cin>>t>>k>>mx;
while(--t){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
mx=x,mi=0;
}
cout<<mx<<endl;
return 0;
}


#include <iostream>
using namespace std;
int main(){
int t,x,mx=0,mi=0;long long k;
cin>>t>>k;
while(t--){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
mx=x,mi=0;
}
cout<<mx<<endl;
return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
short t,x,mx=0;long long k,mi=0;
cin>>t>>k;
for(short i=0;i<t;i++){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
	mx=x,mi=0;
}
cout<<mx<<endl;
return 0;
}


#include <iostream>
using namespace std;
int main(){
short t,x,mx=0,mi=0;long long k;
cin>>t>>k;
while(t--){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
mx=x,mi=1;
}
cout<<mx<<endl;
return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
short t,x,mx=0,mi=0;long long k;
cin>>t>>k;
for(short i=0;i<t;i++){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
	mx=x,mi=0;
}
cout<<mx<<endl;
return 0;
}


#include <iostream>
using namespace std;
int main(){
short t,x,mx=0,mi=0;long long k;
cin>>t>>k>>mx;
while(--t){
cin>>x;
if(mi==k)break;
if(mx>x)mi++;
else
mx=x,mi=1;
}
cout<<mx<<endl;
return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <set>

typedef long long ll;

using namespace std;

int main() {

	ll n, k;
	cin >> n >> k;
	deque<int> d;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		d.push_back(x);
	}
	if (k > n) {
		cout << n;
	}
	else {
		int cur = 0;
		int last_winner = d.front();
		while (cur < k) {
			int top = d.front();
			d.pop_front();
			if (top < d.front()) {
				d.push_back(top);
				cur = 1;
				last_winner = d.front();
			}
			else {
				d.push_back(d.front());
				d.pop_front();
				d.push_front(top);
				cur++;
				last_winner = top;
			}
		}
		cout << last_winner;
	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL a[1005];

int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	string str, str1;

	while(cin>>n>>k){
		for(i=0;i<n;i++){
		cin>>a[i];
		}
		LL max = a[0];
		for(i=0;i<n;i++){
			if(max<a[i])
				max = a[i];
			x = 0;
			for(j=i+1;j<n;j++){
				if(a[i] > a[j])
					x++;
				else
					break;
			}
			if(x >= k){
				max = a[i];
				break;
			}
		}
		cout<<max<<"\n";
	}

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a,long long b){   while(b)b^=a^=b^=a%=b;  return a;   }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = {-1, 0, 1, 0, -1, 1,  1, -1};
int dy[8] = { 0, 1, 0,-1,  1, 1, -1, -1};

LL a[1005];

int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num;
	string str, str1;

	while(cin>>n>>k){
		for(i=0;i<n;i++){
		cin>>a[i];
		}
		/*if(n <= k){
		sort(a,a+n);
		cout<<a[n-1]<<"\n";
		continue;
		}*/

		LL max = a[0];
		for(i=0;i<n;i++){
			if(max<a[i])
				max = a[i];
			x = 0;
			if(i>0){
				if(a[i-1] < a[j])
					x++;
			}
			for(j=i+1;j<n;j++){
				if(a[i] > a[j])
					x++;
				else{
					break;
				}
			}

			if(x >= k){
				max = a[i];
				break;
			}
		}
		cout<<max<<"\n";
	}

	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int k,n;
	while(~scanf("%lld%lld",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		if(k>=n){
			cout<<n<<endl;
			continue;
		}
		long long int ans=0;
		int w=q.front();
		q.pop();
		while(ans<k){
			int a=q.front();
			if(w>a){
				ans++;
				q.push(a);
			}
			else
			{
				ans=1;
				q.push(w);
				w=a;
			}
			q.pop();
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int k;
	int n;
	while(~scanf("%d%lld",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		if(k>=n){
			cout<<n<<endl;
			continue;
		}
		int ans=0;
		int w=q.front();
		q.pop();
		while(ans<=k){
			int a=q.front();
			q.pop();
			if(w>a){
				ans++;
				q.push(a);
			}
			else{
				ans=0;
				q.push(w);
				w=a;
			}
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int k;
	int n;
	while(~scanf("%d%lld",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		int ans=0;
		int w=q.front();
		q.pop();
		if(k>=n){
			cout<<n<<endl;
			continue;
		}
		while(ans<k){
			int a=q.front();
			q.pop();
			if(w>a){
				ans++;
				q.push(a);
			}
			else{
				ans=0;
				q.push(w);
				w=a;
			}
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int k;
	int n;
	while(~scanf("%d%lld",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		if(k>=n){
			cout<<n<<endl;
			continue;
		}
		int ans=0;
		int w=q.front();
		q.pop();
		while(ans<k){
			int a=q.front();
			if(w>a){
				ans++;
				q.push(a);
			}
			else
			{
				ans=0;
				q.push(w);
				w=a;
			}
			q.pop();
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	while(~scanf("%d%d",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		int ans=0;
		int w=q.front();
		q.pop();
//		if(k>n) k=n-1;
		while(ans<k){
			int a=q.front();
			q.pop();
			if(w>a){
				ans++;
				q.push(a);
			}
			else{
				ans=0;
				q.push(w);
				w=a;
			}
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k;
	while(~scanf("%d%d",&n,&k)){
		queue<int>q;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			q.push(a);
		}
		int ans=0;
		int w=q.front();
		q.pop();
		if(k>n) k=n-1;
		while(ans<k){
			int a=q.front();
			q.pop();
			if(w>a){
				ans++;
				q.push(a);
			}
			else{
				ans=0;
				q.push(w);
				w=a;
			}
		}
		printf("%d\n",w);
	}
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < n;i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();
		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.push(b);
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();

		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();

		}
	}
	if (b == 99)
		cout << 100 << endl;
	else
		cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();

		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();
		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < n;i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();
			s =0;
			s++;

		}
	}

		cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < n;i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=1;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();
			s = 1;

		}
	}

		cout << b << endl;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;
int main()
{
	queue<int> q;
	long long n, k, a,b,s=0;
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a;
		q.push(a);

	}
	b = q.front();
	q.pop();
	for (int i = 0;i < q.size();i++)
	{

		if (b > q.front())
		{
			q.push(q.front());
			q.pop();
			s++;
			if (s == k)
				break;
		}
		else
		{
			q.push(b);
			b = q.front();
			q.pop();
			s++;
		}
	}
	cout << b << endl;
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
int n,i,x,l,p=0;
long long k;
cin >> n >> k;
for (i=0;i<n;i++)
{
cin >> x;
if (p<x)
{
if (p==0) l=0;
else l=1;
p=x;

}
if (p>x) l++;
if (l==k) break;
}
cout << p;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, i, k, kol = 0, k1 = 0, j, max = 0, k2;
	cin >> n >> k;
	int a[500];
	for (i = 0; i < n; i++)
		cin >> a[i];
	i = 0;
	while (true)
	{
		if (a[i] > max)
		{
			max = a[i];
			k1 = i;
		}
		for (j = k1; j < n; j++)
		{
			if (kol >= k)
				break;
			if (max < a[j])
			{
				max = a[j];
				k1 = j;
			}
			else kol++;
		}
			if ((kol >= k) || (i == n))
			{
				cout << max;
				break;
			}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, i, k, kol = 0, k1 = 0, j, max = 0, k2;
	cin >> n >> k;
	int a[500];
	for (i = 0; i < n; i++)
		cin >> a[i];
	 max = a[0];
		for (j = 0; j < n; j++)
		{
			if (max < a[j])
			{
				max = a[j];
			}
			else kol++;
			if ((kol >= k) || (j == n - 1))
			{
				cout << max;
				break;
			}

		}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, i, k, kol = 0, k1 = 0, j, max = 0, k2;
	cin >> n >> k;
	int a[500];
	for (i = 0; i < n; i++)
		cin >> a[i];
	 max = a[0];
		for (j = 1; j < n; j++)
		{
			if (max < a[j])
			{
				max = a[j];
				kol = 0;
			}
			else kol++;
			if ((kol >= k) || (j == n - 1))
			{
				cout << max;
				break;
			}

		}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, i, k, kol = 0, k1 = 0, j, max = 0, k2;
	cin >> n >> k;
	int a[500];
	for (i = 0; i < n; i++)
		cin >> a[i];
	i = 0;
	while (true)
	{
		if (a[i] > max)
		{
			max = a[i];
			k1 = i;
		}
		for (j = k1; j < n; j++)
			if (max < a[j])
			{
				max = a[j];
				k1 = j;
			}
			else kol++;
			if ((kol >= k) || (i == n))
			{
				cout << max;
				break;
			}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, i, k, kol = 0, k1 = 0, j, max = 0, k2;
	cin >> n >> k;
	int a[500];
	for (i = 0; i < n; i++)
		cin >> a[i];
	i = 0;
	while (true)
	{
		if (a[i] > max)
		{
			max = a[i];
			k1 = i;
		}
		if (k1 + k >= n)
			k2 = n;
		else k2 = k1 + k;
		for (j = k1; j < k2; j++)
			if (max < a[j])
			{
				max = a[j];
				k1 = j;
				break;
			}
			else kol++;
			if ((kol >= k) || (i == n))
			{
				cout << max;
				break;
			}
	}
	return 0;
}


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	queue <int> players, p;
	long long n, k, prom, max = 0, maxstr = 0, s = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		players.push(prom);
		if (k+1 < n)
		{
			if (k+1 > 0)
			{
				if (prom > max)
					max = prom;
				k--;
			}
		}
		else
			if (prom > max)
				max = prom;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	long long n, k, prom, max = 0, maxstr = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		if (maxstr < k)
			if (prom > max)
			{
				max = prom;
				maxstr = 1;
			}
			else
				maxstr++;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	long long n, k, prom, max = 0, maxstr = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		if (maxstr < k)
			if (prom > max)
			{
				max = prom;
				maxstr = 0;
			}
			else
				maxstr++;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	long long n, k, prom, max = 0, maxstr = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		if (i == 1)
			max = prom;
		else
		if (maxstr < k)
			if (prom > max)
			{
				max = prom;
				maxstr = 1;
			}
			else
				maxstr++;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	queue <int> players, p;
	long long n, k, prom, max = 0, maxstr = 0, s = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		players.push(prom);
		if (maxstr < k)
			if (prom > max)
			{
				max = prom;
			}
			else
				maxstr++;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	long long n, k, prom, max = 0, maxstr = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		if (maxstr < k)
			if (prom >= max)
			{
				max = prom;
				maxstr = 0;
			}
			else
				maxstr++;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	queue <int> players, p;
	unsigned long long n, k, prom, max = 0, maxstr = 0, s = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		players.push(prom);
	}

	while (s < n)
	{
		prom = players.front();
		players.pop();
		if (prom > players.front())
		{
			p.push(prom);
			while (players.size() != 0)
			{
				p.push(players.front());
				players.pop();
			}
			s++;
			if (max < prom)
				max = prom;
			players = p;

		}
		else
		{
			players.push(prom);
			if (max < players.front())
				max = players.front();
			s++;
		}
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	queue <int> players, p;
	long long n, k, prom, max = 0, maxstr = 0, s = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		players.push(prom);
		if (k+1 < n)
		{
			if (k+1 > 0)
			{
				if (prom > max)
					max = prom;
				k--;
			}
		}
		else
			if (prom > max)
				max = prom;
	}

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


/*#define _USE_MATH_DEFINES
#include <iostream>
#include <conio.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <sstream>
#include <queue>

using namespace std;

string lis(vector<string>s)
{
	string last;
	last = "";
	for (auto i = s.begin(); i != s.end(); i++)
	{
		last += *i;
	}
	return last;
}

string clean(string b)
{
	for (int i = 0; i <=b.size()-1; i++)
	{
		if (b[i] != '0')
		{
			b = b.substr(i, b.size() - i);
			break;
		}
	}
	return b;
}
string d(char b, char a,string s, int num)
{
	int prom;
	prom = (b - '0') - (a - '0');

	if (prom >= 0)
		s[num] = prom+'0';
	else
	{
		if (num != 0)
		{
			if (num == 1 && s[0] == '-')
			{
				s = "-" + to_string((s[num] - '0') - prom) + s.substr(2, s.size() - num-1);
			}
			else
			{
				s[num] = 10 + prom + '0';
				s = d(s[num - 1], 1 + '0', s, num - 1);
			}
		}
		else
		{
			s = "-" + to_string(abs((s[num] - '0') + prom)) + s.substr(1, s.size() - num-1);
		}
	}
	return s;
}

string dec(string b, string a)
{
	int j;
	j = a.size() - 1;
	for (int i = b.size() - 1; i >= 0; i--)
	{
		if (j<0)
			break;
		b = d(b[i], a[j], b, i);
		j--;
	}
	return b;
}

bool gcd05(string a, string b, long long k) {

	while (a != b) {
		if (atoi(dec(b,a).c_str()) < 0) {
			string tmp = a;
			a = b;
			b = tmp;
		}
		b = dec(b, a);
		b = clean(b);
	}

	return atoi(dec(a,to_string(k)).c_str())>=0;
}

int main()
{
	long long  N, M, K, m;
	string last, proms;
	vector <string> s;
	last = "";
	long long prom;
	cin >> N >> M >> K;
	m = M;

	for (int i = 1; i <= N; i++)
	{
		cin >> prom;
		s.push_back(to_string(prom));
	}

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

	last = lis(s);

	while (next_permutation(s.begin(), s.end()))
	{
		proms = lis(s);
		if (gcd05(last, proms, K))
			M--;
		if (M == 0)
			break;
	}

	if (m == M)
	{
		cout << -1;
	}
	else
		for (auto i = s.begin(); i != s.end(); i++)
		{
			cout << *i << " ";
		}

	_getch();
	return 0;
}*/
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <queue>
#include <stack>
#include <climits>
#include <deque>
#include <ctime>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{

	queue <int> players, p;
	long long n, k, prom, max = 0, maxstr = 0, s = 0;

	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> prom;
		players.push(prom);
		if (k < n)
		{
			if (k > 0)
			{
				if (prom > max)
					max = prom;
				k--;
			}
		}
		else
			if (prom > max)
				max = prom;
	}

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


#include <iostream>

using namespace std;

int main()
{
	long long n, k, max;
	cin >> n >> k;
	long long mas[1001];
	bool flag = false;
	for (int i = 1; i <= n; i++) cin >> mas[i];
	mas[0] = mas[1];
	if (n >= k)
	{
		for (int i = 1; i <= k; i++) mas[n + i] = mas[i];

		for (int i = 1; i <= n; i++)
		{
			flag = false;
			for (int j = i + 1; j <= k + i; j++)
			{
				if (mas[i] < mas[j]) flag = true;
			}
			if (!flag)
			{
				cout << mas[i];
				return 0;
			}
			flag = false;
			if (i > 1)
			{
				for (int j = i - 1; j < k + i; j++)
				{
					if (mas[i] < mas[j]) flag = true;
				}
				if (!flag)
				{
					cout << mas[i];
					return 0;
				}
			}

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


#include <iostream>

using namespace std;

int main()
{
	long long n, k, max;
	cin >> n >> k;
	long long mas[1001];
	bool flag = false;
	for (int i = 0; i < n; i++) cin >> mas[i];

	if (n >= k)
	{
		for (int i = 0; i < k; i++) mas[n + i] = mas[i];

		for (int i = 0; i < n; i++)
		{
			flag = false;
			for (int j = i + 1; j <= k + i; j++)
			{
				if (mas[i] < mas[j]) flag = true;
			}
			if (!flag)
			{
				cout << mas[i];
				return 0;
			}
		}
	}
	else
	{
		max = mas[0];
		for (int i = 0; i < n; i++)
		{
			if (mas[i] > max) max = mas[i];
		}
		cout << max;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	long long n, k, max;
	cin >> n >> k;
	long long mas[1001];
	bool flag = false;
	for (int i = 1; i <= n; i++) cin >> mas[i];
	mas[0] = mas[1];
	if (n >= k)
	{
		for (int i = 1; i <= k; i++) mas[n + i] = mas[i];

		for (int i = 1; i <= n; i++)
		{
			flag = false;
			for (int j = i + 1; j <= k + i; j++)
			{
				if (mas[i] < mas[j]) flag = true;
			}
			if (!flag)
			{
				cout << mas[i];
				return 0;
			}
			flag = false;
			for (int j = i - 1; j < k + i; j++)
			{
				if (mas[i] < mas[j]) flag = true;
			}
			if (!flag)
			{
				cout << mas[i];
				return 0;
			}

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


#include <iostream>

using namespace std;

int main()
{
	long long n, k, max;
	cin >> n >> k;
	long long mas[1001];
	bool flag = false;
	for (int i = 1; i <= n; i++) cin >> mas[i];
	mas[0] = mas[1];
	if (n >= k)
	{
		for (int i = 1; i <= k; i++) mas[n + i] = mas[i];

		for (int i = 1; i <= n; i++)
		{
			flag = false;
			for (int j = i + 1; j <= k + i; j++)
			{
				if (mas[i] < mas[j]) flag = true;
			}
			if (!flag)
			{
				cout << mas[i];
				return 0;
			}
			flag = false;
			if (i > 1)
			{
				for (int j = i - 1; j < k + i; j++)
				{
					if (mas[i] < mas[j]) flag = true;
				}
				if (!flag)
				{
					cout << mas[i];
					return 0;
				}
			}

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


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n;
	long long int k;
	cin >> n >> k;
	vector<int> S(n);
	for (int i = 0; i < n; ++i)
		cin >> S[i];
	if (k >= n)
		cout << *max_element(S.begin(), S.end());
	else {
		int w = S[0];
		queue<int> Q;
		for (int i = 1; i < n; ++i)
			Q.push(S[i]);
		int k1 = k;
		while (k1 > 0)
			if (w > Q.front()) {
				--k1;
				Q.push(Q.front());
				Q.pop();
			}
			else {
				k1 = k;
				Q.push(w);
				w = Q.front();
				Q.pop();
			}
		cout << w;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n;
	long long int k;
	cin >> n >> k;
	vector<int> S(n);
	for (int i = 0; i < n; ++i)
		cin >> S[i];
	if (k >= n)
		cout << *max_element(S.begin(), S.end());
	else {
		int w = S[0];
		queue<int> Q;
		for (int i = 1; i < n; ++i)
			Q.push(S[i]);
		int k1 = k;
		while (k1 > 0)
			if (w > Q.front()) {
				--k1;
				Q.push(Q.front());
				Q.pop();
			}
			else {
				k1 = k - 1;
				Q.push(w);
				w = Q.front();
				Q.pop();
			}
		cout << w;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int const MAXN = 505;
long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n)
	{
		cout << _max;
		return 0;
	}
	for (;;)
	{
		int cur = 0;
		vector<int> last;
		if (a[0] == _max)
		{
			cout << _max;
			return 0;
		}
		for (int i = 0; i < a.size(); i++)
		{
			if (a[0] < a[i])
			{
				if (i >= k)
				{
					cout << a[0];
					return 0;
				}
				else
				{
					for (int j = i; j < a.size(); j++)
						last.push_back(a[j]);
					for (int j = 0; j < i; j++)
						last.push_back(a[j]);
					swap(last, a);
				}
			}
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n - 1)
	{
		cout << _max;
		return 0;
	}
	if (a[0] == _max)
    {
        cout << a[0];
        return 0;
    }
	int cur = a[0];
	int cnt = 0;
	for (int i = 1;i < n;i++)
    {
        if (cur < a[i])
        {
            cnt = 1;
            cur = a[i];
        }
        else
        {
            cnt++;
        }
        if (cnt == k)
        {
            cout << cur;
            return 0;

        }
    }
    cout << _max;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int const MAXN = 505;
long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n)
	{
		cout << _max;
		return 0;
	}
	for (;;)
	{
		int cur = 0;
		vector<int> last;
		if (a[0] == _max)
		{
			cout << _max;
			return 0;
		}
		for (int i = 0; i < a.size(); i++)
		{
			if (a[0] < a[i])
			{
				if (i >= k)
				{
					cout << a[0];
					return 0;
				}
				else
				{
					for (int j = i; j < a.size(); j++)
						last.push_back(a[j]);
					for (int j = 0; j < i; j++)
						last.push_back(a[j]);
					swap(last, a);
				}
			}
			if (i == k)
			{
				cout << a[0];
				return 0;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int const MAXN = 505;
long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n)
	{
		cout << _max;
		return 0;
	}
	for (;;)
	{
		int cur = 0;
		vector<int> last;
		for (int i = 0; i < a.size(); i++)
		{
			if (a[0] == _max)
			{
				cout << _max;
				return 0;
			}
			if (a[0] < a[i])
			{
				if (i >= k)
				{
					cout << a[0];
					return 0;
				}
			}
			else
			{
				for (int j = i; j < a.size(); j++)
					last.push_back(a[j]);
				for (int j = 0; j < i; j++)
					last.push_back(a[j]);
				swap(last, a);
			}
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n - 1)
	{
		cout << _max;
		return 0;
	}
	for (;;)
	{
		if (a[0] == _max)
		{
			cout << _max;
			return 0;
		}
		for (int i = 0; i < a.size(); i++)
		{
			if (a[0] < a[i])
			{
				if (i >= k)
				{
					cout << a[0];
					return 0;
				}
				else
				{
					vector<int> last;
					for (int j = i; j < a.size(); j++)
						last.push_back(a[j]);
					for (int j = 0; j < i; j++)
						last.push_back(a[j]);
					swap(last, a);
				}
			}
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int const MAXN = 505;
long long n, k;
vector<int> a;

int main()
{
	cin >> n >> k;
	int _max = -1;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a.push_back(t);
		_max = max(t, _max);
	}
	if (k >= n)
	{
		cout << _max;
		return 0;
	}
	for (;;)
	{
		if (a[0] == _max)
		{
			cout << _max;
			return 0;
		}
		for (int i = 0; i < a.size(); i++)
		{
			if (a[0] < a[i])
			{
				if (i >= k)
				{
					cout << a[0];
					return 0;
				}
				else
				{
					vector<int> last;
					for (int j = i; j < a.size(); j++)
						last.push_back(a[j]);
					for (int j = 0; j < i; j++)
						last.push_back(a[j]);
					swap(last, a);
				}
			}
		}
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <queue>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
const int INF = 1000000000;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int main() {
	ll n, k;
	cin >> n >> k;
	if (k > n) {
		int maxEl = -1;
		int a;
		for (int i = 0; i < n; i++) {
			cin >> a;
			maxEl = max(maxEl, a);
		}
		cout << maxEl;
		return 0;
	}
	int a;
	queue <int> q;
		for (int i = 0; i < n; i++) {
			cin >> a;
			q.push(a);
		}
		int t = 0;
		int g1 = q.front(), g2;
		q.pop();
		while (t < k) {
			g2 = q.front();
			q.pop();
			if (g1 > g2) {
				t++;
				q.push(g2);
			}
			else {
				t = 1;
				q.push(g1);
				g1 = g2;
			}
		}
		cout << g1;

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, i, sum, power;
	long long k;
	int a[1000];

	scanf_s("%d%I64d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf_s("%d", &a[i]);
	sum = 0;
	power = a[1];
	for (i = 2; i <= n; i++)
		if (power > a[i])
		{
			sum++;
			if (sum == k) break;
		}
		else
		{
			power = a[i];
			sum = 1;
			if (sum == k) break;
		}
	printf("%d", power);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, k, i, sum, power;
	int a[1000];

	scanf_s("%d%d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf_s("%d", &a[i]);
	sum = 0;
	power = a[1];
	for (i = 2; i <= n; i++)
		if (power > a[i])
		{
			sum++;
			if (sum = k) break;
		}
		else
		{
			power = a[i];
			sum = 1;
			if (sum = k) break;
		}
	printf("%d", power);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
	int n, k, i, sum, power;
	int a[1000];

	scanf_s("%d%d", &n, &k);
	for (i = 1; i <= n; i++)
		scanf_s("%d", &a[i]);
	sum = 0;
	power = a[1];
	for (i = 2; i <= n; i++)
		if (power > a[i])
		{
			sum++;
			if (sum == k) break;
		}
		else
		{
			power = a[i];
			sum = 1;
			if (sum == k) break;
		}
	printf("%d", power);

	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, A[500];
	long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int dem = 0;
	for (int i = 2; (dem < k)&&(dem<n); i++)
	{
		if (A[1] > A[i]) { dem++; }
		else
		{
			dem = 1;
			int tm;
			tm = A[1];
			for (int j =1; j <=(n-1); j++)
			{
				A[j] = A[j +1];
			}
			A[n] = tm;
		}
	}
	cout << A[1];
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, A[500];
	long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int dem = 0;
	for (int i = 2; (dem < k)&&(dem<n); i++)
	{
		if (A[1] > A[i]) { dem++; }
		else
		{
			dem = 0;
			int tm;
			tm = A[n];
			for (int j =n ; j >= 2; j--)
			{
				A[j] = A[j - 1];
			}
			A[1] = tm;
		}
	}
	cout << A[1];
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, A[500];
	long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int dem = 0;
	while ((dem < k) && (dem < n))
	{
		if (A[1] > A[2])
		{
			int tm;
			tm = A[2];
			for (int j = 2; j <= (n - 1); j++)
			{
				A[j] = A[j + 1];
			}
			A[n] = tm;
			dem++;
		}
		if (A[1]<A[2] && dem <k && dem <n)
		{
			dem = 1;
			int tm;
			tm = A[1];
			for (int j = 1; j <= (n - 1); j++)
			{
				A[j] = A[j + 1];
			}
			A[n] = tm;
		}
	}
	cout << A[1];
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, A[501];
	long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int dem = 0;
	while ((dem < k) && (dem < n))
	{
		if (A[1] > A[2])
		{
			int tm;
			tm = A[2];
			for (int j = 2; j <= (n - 1); j++)
			{
				A[j] = A[j + 1];
			}
			A[n] = tm;
			dem++;
		}
		if (A[1]<A[2] && dem <k && dem <n)
		{
			dem = 1;
			int tm;
			tm = A[1];
			for (int j = 1; j <= (n - 1); j++)
			{
				A[j] = A[j + 1];
			}
			A[n] = tm;
		}
	}
	cout << A[1];
	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, A[500];
	long long int k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> A[i];
	}
	int dem = 0;
	for (int i = 2; (dem < k)&&(dem<n); i++)
	{
		if (A[1] > A[i]) { dem++; }
		else
		{
			dem = 0;
			for (int j =2 ; j <= n; j++)
			{
				int tm;
				tm = A[n];
				A[j] = A[j - 1];
				A[1] = tm;
			}
		}
	}
	cout << A[1];
//	system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <queue>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define sqr(a) ((a)*(a))

using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n, m, k;
    cin >> n >> k;
    deque<long long> v;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    if (k >= n - 1) {
        long long maxRes = 0;
        for (int i = 0; i < v.size(); ++i) {
            maxRes = max(v[i], maxRes);
        }
        cout << maxRes << endl;
    }
    else {
        int kNow = 0;
        long long current = max(v[0], v[1]);
        long long last = min(v[0], v[1]);
        v.pop_front();
        v.pop_front();
        v.push_back(last);
        ++kNow;
        while (kNow < k) {
            if (current > v[0]) {
                ++kNow;
                v.push_back(v[0]);
                v.pop_front();
            }
            else {
                kNow = 1;
                v.push_back(current);
                current = v[0];
                v.pop_front();
            }
        }
        cout << current << endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <queue>

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define sqr(a) ((a)*(a))

using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n, m, k;
    cin >> n >> k;
    deque<long long> v;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    if (k >= n - 1) {
        long long maxRes = 0;
        for (int i = 0; i < v.size(); ++i) {
            maxRes = max(v[i], maxRes);
        }
        cout << maxRes << endl;
    }
    else {
        int kNow = 0;
        long long current = max(v[0], v[1]);
        long long last = min(v[0], v[1]);
        v.pop_front();
        v.pop_front();
        v.push_back(last);
        ++kNow;
        while (kNow < k - 1) {
            if (current > v[0]) {
                ++kNow;
                v.push_back(v[0]);
                v.pop_front();
            }
            else {
                kNow = 0;
                v.push_back(current);
                current = v[0];
                v.pop_front();
            }
        }
        cout << current << endl;
    }
    return 0;
}


import java.io.*;
import java.util.*;

public final class codeForces
{

    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        {
            int T=Integer.parseInt(in.readLine());
            while(T-->0)
            {

                int N=Integer.parseInt(in.readLine());
                String S=in.readLine();
                boolean found=false;
                int index=0;

                int k=0;
                int q=0;
                int s=0;
                int i1=-1,i2=-1;
                int present=0;
                String c="abacaba";
                for(int i=0; i<N-6; i++)
                {
                    String X=S.substring(i,i+7);
                    if(X.equals(c))
                    {
                        present++;
                        i1=i; i2=i1+7;
                    }
                    else
                    {
                        if(X.charAt(0)=='a' || X.charAt(0)=='?')
                        {

                        }
                        if(X.charAt(1)=='b' || X.charAt(1)=='?')
                        {

                        }
                        else
                            continue;
                        if(X.charAt(2)=='a' || X.charAt(2)=='?')
                        {
                        }
                        else
                            continue;
                        if(X.charAt(3)=='c' || X.charAt(3)=='?')
                        {

                        }
                        else continue;
                        if(X.charAt(4)=='a' || X.charAt(4)=='?')
                        {

                        }
                        else continue;
                        if(X.charAt(5)=='b' || X.charAt(5)=='?')
                        {

                        }
                        else continue;
                        if(X.charAt(6)=='a' || X.charAt(6)=='?')
                        {

                            k++; //represents total kitni ban skti
                            i1=i;
                            i2=i+7;

                        }
                    }
                }

                if((k>0 && present==0 ) || present==1)
                {
                    System.out.println("YES");
                    if(present==1)
                    {
                       i1=-1;
                       i2=-1;

                    }
                    for(int i=0; i<N; i++)
                    {
                        if(i==i1 )
                        {
                            System.out.print("abacaba");
                            i=i2;
                        }
                        else
                        {
                            if(S.charAt(i)=='?')System.out.print("z");
                            else System.out.print(S.charAt(i));
                        }
                    }
                    System.out.println();
                }
                else

                    System.out.println("NO");

            }

        }
    }
}


import java.io.*;
import java.util.*;

public final class codeForces
{

    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        {
            int T=Integer.parseInt(in.readLine());
            while(T-->0)
            {
                int N=Integer.parseInt(in.readLine());
                String S=in.readLine();
                boolean found=false;
                if(S.contains("abacaba"))
                {
                    found=true;
                }
                int k=0;
                int q=0;
                int s=0;
                int i1=-1,i2=-1;
                int present=0;
                for(int i=0; i<N-6; i++)
                {
                    String X=S.substring(i,i+7);

                    if(X.charAt(0)=='a' || X.charAt(0)=='?')
                    {
                        i1=i;
                        if(X.charAt(0)=='?') q++;
                    }
                    if(X.charAt(1)=='b' || X.charAt(1)=='?')
                    { if(X.charAt(0)=='?') q++;

                    }
                    else
                        continue;
                    if(X.charAt(2)=='a' || X.charAt(2)=='?')
                    { if(X.charAt(0)=='?') q++;
                    }
                    else
                        continue;
                    if(X.charAt(3)=='c' || X.charAt(3)=='?')
                    {
                        if(X.charAt(0)=='?') q++;
                    }
                    else continue;
                    if(X.charAt(4)=='a' || X.charAt(4)=='?')
                    {
                        if(X.charAt(0)=='?') q++;
                    }
                    else continue;
                    if(X.charAt(5)=='b' || X.charAt(5)=='?')
                    {
                        if(X.charAt(0)=='?') q++;
                    }
                    else continue;
                    if(X.charAt(6)=='a' || X.charAt(6)=='?')
                    {
                        if(X.charAt(0)=='?')q++;
                       if(q==0) present++;
                        k++; //represents total kitni ban skti
                        i2=i+7;

                    }
                }
                if(k==1 || present==1)
                {
                    System.out.println("YES");
                    for(int i=0; i<N; i++)
                    {
                        if(i==i1)
                        {
                            System.out.print("ababaca");
                            i=i2;
                        }
                        else
                        {
                            if(S.charAt(i)=='?')System.out.print("d");
                            else System.out.print(S.charAt(i));
                        }
                    }
                    System.out.println();
                }
                else
                    System.out.println("NO");

            }

        }
    }
}


import java.io.*;
import java.util.*;

public final class codeForces
{

    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        {
            int T=Integer.parseInt(in.readLine());
            while(T-->0)
            {
                int N=Integer.parseInt(in.readLine());
                String S=in.readLine();
                boolean found=false;
                int index=0;

                int k=0;
                int q=0;
                int s=0;
                int i1=-1,i2=-1;
                int present=0;
                for(int i=0; i<N-6; i++)
                {
                    String X=S.substring(i,i+7);

                    if(X.charAt(0)=='a' || X.charAt(0)=='?')
                    {
                        i1=i;

                    }
                    if(X.charAt(1)=='b' || X.charAt(1)=='?')
                    {

                    }
                    else
                        continue;
                    if(X.charAt(2)=='a' || X.charAt(2)=='?')
                    {
                    }
                    else
                        continue;
                    if(X.charAt(3)=='c' || X.charAt(3)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(4)=='a' || X.charAt(4)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(5)=='b' || X.charAt(5)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(6)=='a' || X.charAt(6)=='?')
                    {

                        k++; //represents total kitni ban skti
                        i2=i+7;

                    }
                    else continue;
                    if(X.equals("abacaba"))
                    {

                        present++;
                    }
                    else k++;

                }
                int last=0;

                if((k>0 && present==0 ) || present==1)
                {
                    System.out.println("YES");
                    if(present==1)
                    {
                        i1=S.indexOf("abacaba");
                        i2=i1+7;

                    }
                    for(int i=0; i<N; i++)
                    {
                        if(i==i1 )
                        {
                            System.out.print("abacaba");
                            i=i2;
                        }
                        else
                        {
                            if(S.charAt(i)=='?')System.out.print("d");
                            else System.out.print(S.charAt(i));
                        }
                    }
                    System.out.println();
                }
                else

                    System.out.println("NO");

            }

        }
    }
}


import java.io.*;
import java.util.*;

public final class codeForces
{
    static String c="abacaba";
    static  int found(String X)
    {
        int count=0;
        for(int i=0; i<X.length()-6; i++)
            if(X.substring(i,i+7).equals(c))count++;
        return count;
    }

    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        {
            int T=Integer.parseInt(in.readLine());
            while(T-->0)
            {

                int N=Integer.parseInt(in.readLine());
                String S=in.readLine();
                if(found(S)==1)
                {
                    System.out.println("YES");
                    for(int i=0; i<S.length(); i++)
                    {
                        if(S.charAt(i)=='?')System.out.print("d");
                        else System.out.print(S.charAt(i));
                    }
                    System.out.println();
                    continue;
                }
                else if(found(S)>1)
                {
                    System.out.println("NO");
                    continue;
                }
                else if(found(S)==0)
                {
                    int i1=-1;
                    for(int i=0; i<S.length()-6; i++)
                    {
                        String X=S.substring(i,i+7);
                        if(X.charAt(0)=='a' || X.charAt(0)=='?')
                        {
                        }
                        else continue;
                        if(X.charAt(1)=='b' || X.charAt(1)=='?')
                        {
                        }
                        else continue;
                        if(X.charAt(2)=='a' || X.charAt(2)=='?')
                        {
                        }  else continue;
                        if(X.charAt(3)=='c' || X.charAt(3)=='?')
                        {
                        }  else continue;
                        if(X.charAt(4)=='a' || X.charAt(4)=='?')
                        {
                        }  else continue;
                        if(X.charAt(5)=='b' || X.charAt(5)=='?')
                        {
                        }  else continue;
                        if(X.charAt(6)=='a' || X.charAt(6)=='?')
                        {
                           String St=S.substring(0,i)+c+((i+7<N)?S.substring(i+7):"");
                           if(found(St)==1)
                           {
                               i1=i;
                               break;
                           }
                        }
                    }

                    if(i1==-1)System.out.println("NO");
                    else
                    {
                        System.out.println("YES");
                        for(int i=0; i<S.length(); i++)
                        {
                            if(i==i1)
                            {
                                System.out.print(c);
                                i=i+6;
                            }
                            else
                            { if(S.charAt(i)=='?')System.out.print("d");
                                else System.out.print(S.charAt(i));
                            }

                        }
                        System.out.println();
                    }
                }

            }
        }
    }
}
/* StringTokenizer st;
st=new StringTokenizer(in.readLine());
int n=Integer.parseInt(st.nextToken());
int q=Integer.parseInt(st.nextToken());
int c=Integer.parseInt(st.nextToken());
int A[][]=new int[n][3];
for(int i=0; i<n; i++)
{
st=new StringTokenizer(in.readLine());
A[i][0]=Integer.parseInt(st.nextToken());
A[i][1]=Integer.parseInt(st.nextToken());
A[i][2]=Integer.parseInt(st.nextToken());
}
while(q-->0)
{
st=new StringTokenizer(in.readLine());
long t=Long.parseLong(st.nextToken());
int x1=Integer.parseInt(st.nextToken());
int y1=Integer.parseInt(st.nextToken());
int x2=Integer.parseInt(st.nextToken());
int y2=Integer.parseInt(st.nextToken());
long b=0;
for(int i=0; i<n; i++)
{
int x=A[i][0];
int y=A[i][1];

if(x>=x1 && x<=x2 && y>=y1 && y<=y2)
{
b+=(A[i][2]+t)%(c+1);
}
}
System.out.println(b);
}
 */


import java.io.*;
import java.util.*;

public final class codeForces
{

    public static void main(String args[])throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        {
            int T=Integer.parseInt(in.readLine());
            while(T-->0)
            {
                int N=Integer.parseInt(in.readLine());
                String S=in.readLine();
                boolean found=false;
                int index=0;

                int k=0;
                int q=0;
                int s=0;
                int i1=-1,i2=-1;
                int present=0;
                for(int i=0; i<N-6; i++)
                {
                    String X=S.substring(i,i+7);

                    if(X.charAt(0)=='a' || X.charAt(0)=='?')
                    {
                        i1=i;

                    }
                    if(X.charAt(1)=='b' || X.charAt(1)=='?')
                    {

                    }
                    else
                        continue;
                    if(X.charAt(2)=='a' || X.charAt(2)=='?')
                    {
                    }
                    else
                        continue;
                    if(X.charAt(3)=='c' || X.charAt(3)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(4)=='a' || X.charAt(4)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(5)=='b' || X.charAt(5)=='?')
                    {

                    }
                    else continue;
                    if(X.charAt(6)=='a' || X.charAt(6)=='?')
                    {

                        k++; //represents total kitni ban skti
                        i2=i+7;

                    }
                    else continue;
                    if(X.equals("abacaba"))
                    {

                        present++;
                    }
                    else k++;

                }
                int last=0;

                if((k>0 && present==0 ) || present==1)
                {
                    System.out.println("YES");
                    if(present==1)
                    {
                        i1=S.indexOf("abacaba");
                        i2=i1+7;

                    }
                    for(int i=0; i<N; i++)
                    {
                        if(i==i1 )
                        {
                            System.out.print("abacaba");
                            i=i2;
                        }
                        else
                        {
                            if(S.charAt(i)=='?')System.out.print("z");
                            else System.out.print(S.charAt(i));
                        }
                    }
                    System.out.println();
                }
                else

                    System.out.println("NO");

            }

        }
    }
}


//package Problemset.Tag.Strings;

import java.util.Scanner;

public class AcaciusAndString {
    public static void main(String[] args) {
        Scanner fs = new Scanner(System.in);
        int T = fs.nextInt();
        test:
        for (int tt = 0; tt < T; tt++) {
            int n = fs.nextInt();
            char[] word = fs.next().toCharArray();
            outer:
            for (int startPos = 0; startPos + 6 < n; startPos++) {
                char[] created = new char[n];
                for (int i = 0; i < 7; i++) {
                    if (word[startPos + i] != '?' && word[startPos + i] != "abacaba".charAt(i)) {
                        continue outer;
                    }
                    created[startPos + i] = "abacaba".charAt(i);
                }
                for (int i = 0; i < n; i++)
                    if (created[i] == 0) {
                        created[i] = word[i] == '?' ? 'z' : word[i];
                    }
                if (works(created)) {
                    System.out.println("Yes");
                    System.out.println(created);
                    continue test;
                }
            }
            System.out.println("No");
        }
    }
    static boolean works(char[] a) {
        int times = 0;
        outer:
        for (int i = 0; i + 6 < a.length; i++) {
            boolean works = true;
            for (int j = 0; j < 7; j++) {
                if (a[i + j] != "abacaba".charAt(j)) works = false;
            }
            if (works) times++;
        }
        return times == 1;
    }

}


import java.util.Scanner;
public class AcaciusAndString {
    public static void main(String[] args) {
        Scanner fs = new Scanner(System.in);
        int T = fs.nextInt();
        test:
        for (int tt = 0; tt < T; tt++) {
            int n = fs.nextInt();
            char[] word = fs.next().toCharArray();
            outer:
            for (int startPos = 0; startPos + 6 < n; startPos++) {
                char[] created = new char[n];
                for (int i = 0; i < 7; i++) {
                    if (word[startPos + i] != '?' && word[startPos + i] != "abacaba".charAt(i)) {
                        continue outer;
                    }
                    created[startPos + i] = "abacaba".charAt(i);
                }
                for (int i = 0; i < n; i++)
                    if (created[i] == '') {
                        created[i] = word[i] == '?' ? 'z' : word[i];
                    }
                if (works(created)) {
                    System.out.println("Yes");
                    System.out.println(created);
                    continue test;
                }
            }
            System.out.println("No");
        }
    }
    static boolean works(char[] a) {
        int times = 0;
        outer:
        for (int i = 0; i + 6 < a.length; i++) {
            boolean works = true;
            for (int j = 0; j < 7; j++) {
                if (a[i + j] != "abacaba".charAt(j)) works = false;
            }
            if (works) times++;
        }
        return times == 1;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Ques1 {
    private static int numTimes(String s, String p){
        int i, k=0, n=p.length();
        for(i=0;i<n-6;i++){
            if(p.substring(i, i+7).equals(s)){
                k++;
            }
        }
        return k;
    }
    public static void main(String[] args) throws Exception {
        BufferedReader z = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(z.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(z.readLine()), i, j, k;
            String s = "abacaba", p = z.readLine();
            k = numTimes(s, p);
            if (k > 1) {
                System.out.println("No");
                continue;
            }
            for (i = 0; i < n - 6; i++) {
                for (j = i; j <= i + 6; j++) {
                    if (p.charAt(j) != '?' && p.charAt(j) != s.charAt(j - i)) {
                        break;
                    }
                }
                if (j <= i + 6) {
                    continue;
                }
                StringBuilder l = new StringBuilder(p);
                for (j = i; j <= 6; j++) {
                    l.setCharAt(j, s.charAt(j - i));
                }
                k = numTimes(s, l.toString());
                if (k == 1) {
                    System.out.println("Yes");
                    for (j = 0; j < n; j++) {
                        if (l.charAt(j) == '?') {
                            l.setCharAt(j, 'z');
                        }
                    }
                    System.out.println(l);
                    break;
                }
            }
            if (k != 1) {
                System.out.println("No");
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Ques1 {
    private static int numTimes(String s, String p) {
        int i, k = 0, n = p.length();
        for (i = 0; i < n - 6; i++) {
            if (p.substring(i, i + 7).equals(s)) {
                k++;
            }
        }
        return k;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader z = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(z.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(z.readLine()), i, j, k;
            String s = "abacaba", p = z.readLine();
            k = numTimes(s, p);
            if (k > 1) {
                System.out.println("No");
                continue;
            }
            for (i = 0; i < n - 6; i++) {
                for (j = i; j <= i + 6; j++) {
                    if (p.charAt(j) != '?' && p.charAt(j) != s.charAt(j - i)) {
                        break;
                    }
                }
                if (j <= i + 6) {
                    continue;
                }
                StringBuilder l = new StringBuilder(p);
                for (j = i; j <= i+6; j++) {
                    l.setCharAt(j, s.charAt(j - i));
                }
                k = numTimes(s, l.toString());
                if (k == 1) {
                    System.out.println("Yes");
                    for (j = 0; j < n; j++) {
                        if (l.charAt(j) == '?') {
                            l.setCharAt(j, 'z');
                        }
                    }
                    System.out.println(l);
                    break;
                }
                k=0;
            }
            if (k != 1) {
                System.out.println("No");
            }
        }
    }
}


// Working program using Reader Class

import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main1 {
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        private void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

    static class Hero {
        int pow, end;

        Hero(int a, int b) {
            pow = a;
            end = b;
        }
    }

    static class Tree {
        Tree left, right;
        int st, en, num;

        Tree(int a, int b, int c) {
            st = a;
            en = b;
            num = c;
        }
    }

    private static void upd(Tree tr, int pos, int val) {
        tr.num += val;
        if (tr.st == tr.en) {
            return;
        }
        int mid = (tr.st + tr.en) / 2;
        if (pos <= mid) {
            if (tr.left == null) {
                tr.left = new Tree(tr.st, mid, 0);
            }
            upd(tr.left, pos, val);
        } else {
            if (tr.right == null) {
                tr.right = new Tree(mid + 1, tr.en, 0);
            }
            upd(tr.right, pos, val);
        }
    }

    private static int query(Tree tr, int siz) {
        if (tr == null) {
            return 0;
        }
        tr.num--;
        if (tr.st == tr.en) {
            return tr.st;
        }
        if (tr.left == null) {
            return query(tr.right, siz);
        }
        if (tr.left.num >= siz) {
            return query(tr.left, siz);
        }
        return query(tr.right, siz - tr.left.num);
    }

    private static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    static int find(int a, int[] par) {
        if (par[a] == 0) {
            return a;
        }
        return par[a] = find(par[a], par);
    }

    static void union(int a, int b, int[] par, int[] rank) {
        if (rank[a] >= rank[b]) {
            par[b] = a;
            rank[a] += rank[b];
        } else {
            par[a] = b;
            rank[b] += rank[a];
        }
    }

    private static int numTimes(String s, String p){
        int i, k=0, n=p.length();
        for(i=0;i<n-6;i++){
            if(p.substring(i, i+7).equals(s)){
                k++;
            }
        }
        return k;
    }
    public static void main(String[] args) throws IOException {
        Reader z = new Reader();
        int t=z.nextInt();
        while(t-->0) {
            int n=z.nextInt(), i, j, k;
            String s = "abacaba", p=z.readLine();
            k=numTimes(s, p);
            if(k>1){
                System.out.println("No");
                continue;
            }
            for(i=0;i<n-6;i++){
                for(j=i;j<=i+6;j++){
                    if(p.charAt(j)!='?' && p.charAt(j)!=s.charAt(j-i)){
                        break;
                    }
                }
                if(j<=i+6){
                    continue;
                }
                StringBuilder l = new StringBuilder(p);
                for(j=i;j<=6;j++){
                    l.setCharAt(j, s.charAt(j-i));
                }
                k=numTimes(s, l.toString());
                if(k==1){
                    System.out.println("Yes");
                    for(j=0;j<n;j++){
                        if(l.charAt(j)=='?'){
                            l.setCharAt(j, 'z');
                        }
                    }
                    System.out.println(l);
                    break;
                }
            }
            if(k!=1){
                System.out.println("No");
            }
        }
        z.close();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
 //       sc.nextLine();
        for(int q=0;q<t;q++)
        {
            int n=sc.nextInt();
            sc.nextLine();
            String str=sc.nextLine();
 //           System.out.println(str);
            boolean flag=false;
            String sol="";
            int c=-1;
            String temp="";
            if(flag==false)
            for(int i=3;i<str.length()-3;i++)
            {
                temp="";
                if(str.charAt(i)=='?'||str.charAt(i)=='c')
                {
                    if((str.charAt(i-3)=='?'||str.charAt(i-3)=='a')&&(str.charAt(i-2)=='?'||str.charAt(i-2)=='b')&&(str.charAt(i-1)=='?'||str.charAt(i-1)=='a')&&(str.charAt(i+1)=='?'||str.charAt(i+1)=='a')&&(str.charAt(i+2)=='?'||str.charAt(i+2)=='b')&&
(str.charAt(i+3)=='?'||str.charAt(i+3)=='a')                     )
                    {
                        c=i;
               //         flag=true;
                        for(int j=0;j<i-3;j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                temp=temp.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                temp=temp.concat("x");
                        }
                        temp=temp.concat("abacaba");
                        for(int j=i+4;j<str.length();j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                temp=temp.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                temp=temp.concat("x");
                        }
 //                       System.out.println(temp);
                       //System.out.println((temp.substring(0,i)+temp.substring(i+1,temp.length()))+" "+(temp.substring(0,i)+temp.substring(i+1,temp.length())).contains("abacaba"));
                        if((temp.substring(0,i)+temp.substring(i+1,temp.length())).contains("abacaba")==false)
                        {
                            sol=temp;
                            flag=true;
          //                  System.out.println("hi");
                            break;
                        }
                    }
                }
            }

            if(flag==false)
                System.out.println("No");

            else
            {
                System.out.println("Yes");
                System.out.println(sol);
            }

        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
 //       sc.nextLine();
        for(int q=0;q<t;q++)
        {
            int n=sc.nextInt();
            sc.nextLine();
            String str=sc.nextLine();
 //           System.out.println(str);
            boolean flag=false;
            String sol="";
            int c=-1;
            for(int i=3;i<str.length()-3;i++)
            {
                if(str.charAt(i)=='c')
                {
                    if((str.charAt(i-3)=='?'||str.charAt(i-3)=='a')&&(str.charAt(i-2)=='?'||str.charAt(i-2)=='b')&&(str.charAt(i-1)=='?'||str.charAt(i-1)=='a')&&(str.charAt(i+1)=='?'||str.charAt(i+1)=='a')&&(str.charAt(i+2)=='?'||str.charAt(i+2)=='b')&&
(str.charAt(i+3)=='?'||str.charAt(i+3)=='a')                     )
                    {
                        c=i;
                        flag=true;
                        for(int j=0;j<i-3;j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                sol=sol.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                sol=sol.concat("x");
                        }
                        sol=sol.concat("abacaba");
                        for(int j=i+4;j<str.length();j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                sol=sol.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                sol=sol.concat("x");
                        }
                        break;
                    }
                }
            }
            if(flag==false)
            for(int i=3;i<str.length()-3;i++)
            {
                if(str.charAt(i)=='?')
                {
                    if((str.charAt(i-3)=='?'||str.charAt(i-3)=='a')&&(str.charAt(i-2)=='?'||str.charAt(i-2)=='b')&&(str.charAt(i-1)=='?'||str.charAt(i-1)=='a')&&(str.charAt(i+1)=='?'||str.charAt(i+1)=='a')&&(str.charAt(i+2)=='?'||str.charAt(i+2)=='b')&&
(str.charAt(i+3)=='?'||str.charAt(i+3)=='a')                     )
                    {
                        c=i;
                        flag=true;
                        for(int j=0;j<i-3;j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                sol=sol.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                sol=sol.concat("x");
                        }
                        sol=sol.concat("abacaba");
                        for(int j=i+4;j<str.length();j++)
                        {
                            if(str.charAt(j)!='?')
                            {
                                sol=sol.concat(Character.toString(str.charAt(j)));
                            }
                            else
                                sol=sol.concat("x");
                        }
                        break;
                    }
                }
            }
            if(c>-1)
                 str=str.substring(0,c).concat(str.substring(c+1,str.length()));
            if(flag==false)
                System.out.println("No");

            else if(str.contains("abacaba"))
                System.out.println("No");
            else
            {
                System.out.println("Yes");
                System.out.println(sol);
            }

        }
    }
}