#include <bits/stdc++.h>
using namespace std;
#define loop(i,N) for(int i=0;i<N;i++)
#define lli long long int

int main() {
	lli n,k;
	cin>>n>>k;
	int ar[n];
	int ans=0;
	loop(i,n)	cin>>ar[i], ans=(ar[i]>ans)?ar[i]:ans;
	loop(i,n){
		int j=i+1;
		lli cnt=0;
		while(j<n and ar[i]>ar[j])
			j++,cnt++;
		if(j==n){
			j=0;
			while(j<i and ar[j]<ar[i])
				j++,cnt++;
		}
		if(cnt>=k){
			ans=ar[i];
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,N) for(int i=0;i<N;i++)
#define lli long long int

int main() {
	lli n,k;
	cin>>n>>k;
	int ar[n],m=0;
	loop(i,n)	cin>>ar[i], m=(ar[i]>m)? ar[i]: m ;
	lli ans=0;
	loop(i,n){
		lli j=i+1;
		while(j<n and ar[i]>ar[j])
			j++;
		if((j-1ll*i)>=k){
			ans=1ll*ar[i];
			break;
		}
	}
	if(ans)
		cout<<ans<<endl;
	else
		cout<<m<<endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n,power;
    long long k;
    int p1,p2;
    int currentPlayer;
    int max = 0;
    int win = 0;
    queue <int> line;

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> power;
        line.push(power);
        if (max<=power){
            max = power;
        }
    }

    currentPlayer = line.front();
    line.pop();

    while ((win<k) && (max != currentPlayer)){
        p2 = line.front();
        line.pop();
        if (currentPlayer < p2){
            currentPlayer = p2;
            win = 1;
            line.push(currentPlayer);
        }
        else {
            win++;
            line.push(p2);
        }
    }

    cout << line.front();
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long long k;
    int power,n,p1,p2;
    int max;

    int loop;

    cin >> n >> k;
    int line[n];

    for (int i = 0; i < n; i++) {
        cin >> power;
        line[i]= power;
    }

    if (k>=n-1){
        loop = n;
    }
    else {

        loop = k+1;
    }

    max = line[0];
    for (int i = 1; i <loop; i++) {
        if (max < line[i]){
            max = line[i];
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n,power;
    long long k;
    int p1,p2;
    int currentPlayer;
    int max = 0;
    int win = 0;
    queue <int> line;

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> power;
        line.push(power);
        if (max<=power){
            max = power;
        }
    }

    currentPlayer = line.front();
    line.pop();

    while ( (win<k) && (max != currentPlayer)){
        p2 = line.front();
        line.pop();
        if (currentPlayer < p2){
            line.push(currentPlayer);
            currentPlayer = p2;
            win = 1;
        }
        else {
            win++;
            line.push(p2);
        }
    }

    cout << currentPlayer;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n,power;
    long long k;
    int p1,p2;
    int currentPlayer;
    int max = 0;
    int win = 0;
    queue <int> line;

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> power;
        line.push(power);
        if (max<=power){
            max = power;
        }
    }

    currentPlayer = line.front();
    line.pop();

    while ((win<k) && (max != currentPlayer)){
        p2 = line.front();
        line.pop();
        if (currentPlayer < p2){
            currentPlayer = p2;
            win = 1;
            line.push(max);
        }
        else {
            win++;
            line.push(p2);
        }
    }

    cout << line.front();
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long long k;
    int power,n,p1,p2;
    int max;

    int loop;

    cin >> n >> k;
    int line[n];

    for (int i = 0; i < n; i++) {
        cin >> power;
        line[i]= power;
    }

    if (k>=n-1){
        loop = n;
    }
    else {
        loop = k;
    }

    max = line[0];
    for (int i = 1; i < loop; i++) {
        if (max < line[i]){
            max = line[i];
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long long n,k, power;
    int p1,p2;
    int max;

    int loop;

    cin >> n >> k;
    int line[n];

    for (int i = 0; i < n; i++) {
        cin >> power;
        line[i]= power;
    }

    if (k>=n){
        loop = n;
    }
    else {
        loop = k;
    }

    max = line[0];
    for (int i = 1; i < loop; i++) {
        if (max < line[i]){
            max = line[i];
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long long k;
    int power,n,p1,p2;
    int max;

    int loop;

    cin >> n >> k;
    int line[n];

    for (int i = 0; i < n; i++) {
        cin >> power;
        line[i]= power;
    }

    if (k>=n-1){
        loop = n;
    }
    else {
        loop = k;
    }

    max = line[0];
    for (int i = 1; i <=loop; i++) {
        if (max < line[i]){
            max = line[i];
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long long k;
    int power,n,p1,p2;
    int max;

    int loop;

    cin >> n >> k;
    int line[n];

    for (int i = 0; i < n; i++) {
        cin >> power;
        line[i]= power;
    }

    if (k>=n){
        loop = n;
    }
    else {
        loop = k;
    }

    max = line[0];
    for (int i = 1; i <= loop; i++) {
        if (max < line[i]){
            max = line[i];
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {

    long n,k, power;
    int p1,p2;
    int max;
    queue<int> line;

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> power;
        line.push(power);
    }

    p1 = line.front();
    max = p1;
    line.pop();

    for (int i=0; i< k; i++){
        p2 = line.front();
        line.pop();
        if (max<p2){
            max = p2;
            line.push(max);
        }
        else {
            line.push(p2);
        }
    }

    cout << max;
    /* code */
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > log2(n)){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        for(int i = 0;i < k + 1;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > n){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        int win = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            if(ans < a){
                win = 1;
                ans = a;
            }else{
                win++;
            }
            if(win ==  k){
                printf("%d",ans);
                return 0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > n){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        int win = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            if(ans < a){
                if(i == 0) {
                    win = 0;
                    ans = a;
                } else{
                    win = 1;
                    ans = a;
                }
            }else{
                win++;
            }
            if(win ==  k){
                printf("%d",ans);
                return 0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    //int flag[1000];
    scanf("%d%I64d",&n,&k);
    if(k > log2(n)){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        for(int i = 0;i < k;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > log2(n)){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        int win = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            if(ans < a){
                win = 1;
                ans = a;
            }else{
                win++;
            }
            if(win ==  k){
                printf("%d",ans);
                return 0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > log2(n)){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        int win = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            if(ans < a){
                ans = a;
                win = 0;
                ans = a;
            }else{
                win++;
            }
            if(win ==  k){
                printf("%d",ans);
                return 0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int n ;
    ll k;
    int a[505];
    while(scanf("%d %I64d" , &n , &k) == 2) {
        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<algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
int main(){
    int n,a;
    ll k;
    int ans = 0;
    scanf("%d%I64d",&n,&k);
    if(k > n){
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            ans = max(ans,a);
        }
    }else{
        int win = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",&a);
            if(ans < a){
                win = 0;
                ans = a;
            }else{
                win++;
            }
            if(win ==  k){
                printf("%d",ans);
                return 0;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[10000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=0;
		for(int i=1;i<=k;i++){
			if(a[i]>ans) ans=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=a[1],i=1,j=1;
		while(1){
			i++;j++;
			if(ans<a[j]){
				i=1;ans=a[j];
			}
			if(j==n+1||i==k+1) break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=0;
		for(int i=1;i<=k;i++){
			if(a[i]>ans) ans=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=a[1],i=1,j=1;
		while(1){
			i++;j++;
			if(ans<a[j]){
				i=1;ans=a[j];
			}
			if(j==n||i==k+1) break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=0;
		for(int i=1;i<=k+1;i++){
			if(a[i]>ans) ans=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
long long n,a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(k>=n){
		sort(a+1,a+n+1);
		cout<<a[n]<<endl;
	}
	else{
		int ans=a[1],i=1,j=1;
		while(1){
			i++;j++;
			if(ans<a[j]){
				i=2;ans=a[j];
			}
			if(j==n||i==k+1) break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    if (k >= n-1) { printf("%d", n); exit(0); }
    int p = 0;
    while (true) {
        bool flag = false;
        for (int i = p+1; i < min(p+1+(int)k, n); ++i) {
            if (a[i] > a[p]) {
                flag = true, p = i;
                break;
            }
        }
        if (!flag) { printf("%d", a[p]); break; }
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

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

    k = min(k, (LL)n);

    queue<int> q;
    for (int i = 0; i < n; ++i) q.push(a[i]);

    int x = q.front(); q.pop();
    while (true) {
        int cnt = 0;
        while (cnt < k) {
            int y = q.front(); q.pop();
            if (y < x) {
                q.push(y);
                ++cnt;
                if (cnt == k) { printf("%d\n", x); exit(0); }
            }
            else {
                q.push(x);
                x = y;
                break;
            }
        }
    }
//    int p = 0;
//    while (true) {
//        bool flag = false;
//        int i = p+1;
//        for (; i < min(p+1+(int)k, n); ++i) {
//            if (a[i] > a[p]) {
//                flag = true, p = i;
//                break;
//            }
//        }
//        if (!flag) { printf("%d", a[p]); break; }
//    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

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

    if (k >= n-1) { printf("%d", n); exit(0); }

    queue<int> q;
    for (int i = 0; i < n; ++i) q.push(a[i]);

    int x = q.front(); q.pop();
    while (true) {
        int cnt = 0;
        while (!q.empty() && cnt < k) {
            int y = q.front(); q.pop();
            if (y < x) {
                q.push(y);
                ++cnt;
                if (cnt == k) { printf("%d\n", x); exit(0); }
            }
            else {
                q.push(x);
                x = y;
                break;
            }
        }
    }
//    int p = 0;
//    while (true) {
//        bool flag = false;
//        int i = p+1;
//        for (; i < min(p+1+(int)k, n); ++i) {
//            if (a[i] > a[p]) {
//                flag = true, p = i;
//                break;
//            }
//        }
//        if (!flag) { printf("%d", a[p]); break; }
//    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    if (k >= n-1) { printf("%d", n); exit(0); }
    int p = 0;
    while (true) {
        bool flag = false;
        int i = p+1;
        for (; i < min(p+1+(int)k, n); ++i) {
            if (a[i] > a[p]) {
                flag = true, p = i;
                break;
            }
        }
        if (i == n+1 || !flag) { printf("%d", a[p]); break; }
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

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

    if (k >= n-1) { printf("%d\n", n); exit(0); }

    int p = 0, cnt = 0;
    while (true) {
        bool flag = false;
        int i = p+1;
        for (; i < n && cnt < k; ++i, ++cnt) {
            if (a[i] > a[p]) {
                flag = true, p = i, cnt = 1;
                break;
            }
        }
        if (!flag) { printf("%d", a[p]); break; }
    }

    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);
    if (k >= n-1) { printf("%d", n); exit(0); }
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int p = 0;
    while (true) {
        bool flag = false;
        for (int i = p+1, cnt=0; cnt < k && i < n; ++cnt, ++i) {
            if (a[i] > a[p]) { flag = true; p = i; break; }
        }
        if (!flag) { printf("%d\n", a[p]); exit(0); }
    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

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

    if (k >= n-1) { printf("%d\n", n); exit(0); }

    queue<int> q;
    for (int i = 0; i < n; ++i) q.push(a[i]);

    int x = q.front(); q.pop();
    while (true) {
        int cnt = 0;
        while (!q.empty() && cnt < k) {
            int y = q.front(); q.pop();
            if (y < x) {
                q.push(y);
                ++cnt;
                if (cnt == k) { printf("%d\n", x); exit(0); }
            }
            else {
                q.push(x);
                x = y;
                break;
            }
        }
    }
//    int p = 0;
//    while (true) {
//        bool flag = false;
//        int i = p+1;
//        for (; i < min(p+1+(int)k, n); ++i) {
//            if (a[i] > a[p]) {
//                flag = true, p = i;
//                break;
//            }
//        }
//        if (!flag) { printf("%d", a[p]); break; }
//    }
    return 0;
}


#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int a[maxn];
typedef long long LL;
int main() {
    int n; LL k;
    scanf("%d%I64d", &n, &k);

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

    if (k >= n-1) { puts("0"); exit(0); }

    int p = 0, cnt = 0;
    while (true) {
        bool flag = false;
        int i = p+1;
        for (; i < n && cnt < k; ++i, ++cnt) {
            if (a[i] > a[p]) {
                flag = true, p = i, cnt = 1;
                break;
            }
        }
        if (!flag) { printf("%d", a[p]); break; }
    }

    return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;
int c;
int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n-1)
	{
		cout << *max_element(a, a+n);
		return 0;
	}

	else
	{
		ans = a[0];
		for(int i=1;i<n;i++)
		{
			if(c==k-1)
				break;
			if(ans > a[i])
				c++;
			else
			{
				ans = a[i];
				c = 0;
			}
		}
	}
	cout << ans << "\n";
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];

	forn(i, n)
		cin >> a[i];

	if(k>=n)
	{
		cout << *max_element(a, a+n);
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			for(int j=i+1;j<k;j++)
			{
				if(a[i] > a[j])
					c++;
			}
			if(c==k-1)
			{
				cout << a[i] << "\n";
				return 0;
			}
		}
	}
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];

	if(k>=n)
	{
		cout << *max_element(a, a+n);
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			for(int j=i+1;j<k;j++)
			{
				if(a[i] > a[j])
					c++;
			}
			if(c==k-1)
			{
				flag = 1;
				cout << a[i] << "\n";
				return 0;
			}
		}
	}
	if(!flag)
	{
		cout << *max_element(a, a+n) << "\n";
	}
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;
int c;
int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n-1)
	{
		cout << *max_element(a, a+n);
		return 0;
	}

	else
	{
		ans = a[0];
		for(int i=1;i<n;i++)
		{
			if(ans > a[i])
			{
				c++;
			}
			else
			{
				ans = a[i];
				c++;
			}
			if(c==k)
			{
				cout << ans << "\n";
				return 0;
			}
		}
	}
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
typedef long long ll;
using namespace std;

int main()
{
	ll n, k;

	cin >> n >> k;
	int a[n+1];
	forn(i, n)
		cin >> a[i];
	int ans = 0;

	while(ans<n && k>0)
	{
		if(a[ans] > a[ans+1])
		{
			k--;
			if(k==0 || ans+1==n-1)
			{
				cout << a[ans] << "\n";
				return 0;
			}
		}
		else
		{
			k = 0;
			ans = ans + 1;

		}
	}
	cout << a[ans] << "\n";

}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
typedef long long ll;
using namespace std;

int main()
{
	ll n, k;

	cin >> n >> k;
	ll t = k;
	int a[n+1];
	forn(i, n)
		cin >> a[i];
	int ans = 0;

	while(ans<n && k>0)
	{
		if(a[ans] > a[ans+1])
		{
			t--;
			if(t==0 || ans+1==n-1)
			{
				cout << a[ans] << "\n";
				return 0;
			}
		}
		else
		{
			t = k;
			ans = ans + 1;
			if(ans==n-1)
			{
				cout << a[ans] << "\n";
				return 0;
			}

		}
	}

}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;
int c;
int main()
{
	ll n, k, ab, m=0, a;
	cin >> n >> k >> ab;

	while(--n)
	{
		cin >> a;
		if(m==k)
			break;
		if(ab > a) {m++;}
		else
			ab=a,m=1;
	}
	cout << ab;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n-1)
	{
		cout << *max_element(a, a+n);
		return 0;
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			//cout << "At: " << a[i] << "\n";
			for(int j=i+1;j<=i+k;j++)
			{
				if(a[i] > a[j])
				{
					c++;
				}
				if(a[j]<a[j-1])
					c++;
				else
					break;
			}
			if(c==k)
			{
				ans = i;
				break;
			}
		}
	}
	if(ans >= 0) cout << a[ans] << "\n";
	else cout << *max_element(a, a+n);
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n)
	{
		cout << *max_element(a, a+n);
		return 0;
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			//cout << "At: " << a[i] << "\n";
			for(int j=i+1;j<=i+k;j++)
			{
				if(a[i] > a[j])
				{
					c++;
				}
				else
					break;
			}
			if(c==k)
			{
				ans = i;
				break;
			}
		}
	}
	if(ans >= 0) cout << a[ans] << "\n";
	else cout << *max_element(a, a+n);
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n)
	{
		cout << *max_element(a, a+n);
		return 0;
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			for(int j=i+1;j<=k;j++)
			{
				if(a[i] > a[j])
				{
					//cout << a[i] << " " << a[j] << " " << "\n";
					c++;
					//cout << "C: " << c << "\n";
				}
				else
					break;
			}
			if(c==k)
			{
				ans = i;
				break;
			}
		}
	}
	if(ans >= 0) cout << a[ans] << "\n";
	else cout << *max_element(a, a+n);
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
typedef long long ll;
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;

int main()
{
	ll n, k;
	cin >> n >> k;
	int a[n+1];
	bool flag = 0;

	forn(i, n)
		cin >> a[i];
	int ans = -1;

	if(k>=n)
	{
		cout << *max_element(a, a+n);
		return 0;
	}
	else
	{
		for(int i=0;i<n-k;i++)
		{
			int c = 0;
			for(int j=i+1;j<=k;j++)
			{
				if(a[i] > a[j])
				{
					//cout << a[i] << " " << a[j] << " " << "\n";
					c++;
					//cout << "C: " << c << "\n";
				}
				else
					break;
			}
			if(c==k)
			{
				ans = i;
				break;
			}
		}
	}
	if(ans > 0) cout << a[ans] << "\n";
	else cout << *max_element(a, a+n);
}


#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
typedef long long ll;
using namespace std;

int main()
{
	ll n, k;

	cin >> n >> k;
	ll t = k;
	int a[n+1];
	forn(i, n)
		cin >> a[i];
	int ans = 0;

	while(ans<n && k>0)
	{
		if(a[ans] > a[ans+1])
		{
			t--;
			if(k==0 || ans+1==n-1)
			{
				cout << a[ans] << "\n";
				return 0;
			}
		}
		else
		{
			t = k;
			ans = ans + 1;

		}
	}
	cout << a[ans] << "\n";

}


#include <iostream>
#include <algorithm>
using namespace std;

int n;
long long k;
const int MAXN = 505;
int powers[MAXN];

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k, curr = powers[0], counter = 1;
	while(temp > 0)
	{
		if(curr > powers[counter])
		{
			temp--;
			counter++;
		}
		else
		{
			curr = powers[counter];
			temp = k;
		}
	}

	cout << curr << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int n;
long long k;
const int MAXN = 1005;
int powers[MAXN];

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k, ans = powers[0];
	for(int i = 1; i < n; i++)
	{
		if(powers[i] > ans)
		{
			ans = powers[i];
			temp = k;
		}
		else
			temp--;
		if(temp == 0)
			break;
	}

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int n;
long long k;
const int MAXN = 1005;
int powers[MAXN];

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k - 1, ans = max(powers[0], powers[1]);
	for(int i = 2; i < n; i++)
	{
		if(powers[i] > ans)
		{
			ans = powers[i];
			temp = k;
		}
		else
			temp--;
		if(temp == 0)
			break;
	}

	cout << ans << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int n;
long long k;
const int MAXN = 1005;
int powers[MAXN];

int main()
{
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> powers[i];

	int ans = powers[0], b = 0;
	for(int i = 1; i < n; i++)
	{
		if(powers[i] > ans)
		{
			b = 1;
			ans = powers[i];
		}
		else
			b++;
		if(b == k)
			break;
	}

	cout << ans << "\n";
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k;
	while(temp > 0)
	{
		if(powers[0] > powers[1])
		{
			powers.push_back(powers[1]);
			powers.erase(1);
			temp--;
		}
		else
		{
			powers.push_back(powers[0]);
			powers.erase(0);
			temp = k;
		}
	}

	cout << powers[0] << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n;
long long k;
const int MAXN = 1005;
vector<int> powers;

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k, curr = 0, counter = 1;
	while(temp > 0)
	{
		if(powers[curr] > powers[counter])
		{
			powers.push_back(powers[1]);
			counter++;
			temp--;
		}
		else
		{
			powers.push_back(powers[0]);
			curr = counter;
			counter++;
			temp = k;
		}
	}

	cout << powers[0] << "\n";

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int n, k;
const int MAXN = 505;
int powers[MAXN];

int main()
{
	int big = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> powers[i];
		big = max(big, powers[i]);
	}

	if(k >= n)
	{
		cout << big << "\n";
		return 0;
	}

	int temp = k, curr = powers[0], counter = 1;
	while(temp > 0)
	{
		if(curr > powers[counter])
		{
			temp--;
			counter++;
		}
		else
		{
			curr = powers[counter];
			temp = k;
		}
	}

	cout << curr << "\n";

	return 0;
}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int n,k,x=0,y=0,z=0,d=0,f=0;
    cin>>n>>k;
    ll int a[n],max=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    if(k>n)
    {
        cout<<max;
    }
    else
    {
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<x)
            {
                y++;
                if(y==k)
                {
                    z=a[i];
                    d=1;
                    break;
                }
                if(j==n-1)
                {
                     z=a[i];
                    f=1;
                    break;
                }

            }
            else
            {
                z=a[j];
                break;
            }
        }
        if(d==1 || f==1)
        {
            break;
        }

    }
    cout<<z;
    }

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int n,k,x=0,y=0,z=0,d=0;
    cin>>n>>k;
    ll int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
         x=a[i];
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<x)
            {
                y++;
                if(y==k)
                {
                    z=a[i];
                    d=1;
                    break;
                }
                if(j==n-1)
                {
                     z=a[i];
                    break;
                }

            }
            else
            {
                z=a[j];
                break;
            }
        }
        if(d==1)
        {
            break;
        }

    }
    cout<<z;

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int n,k,x=0,y=0,z=0,d=0,f=0;
    cin>>n>>k;
    ll int a[n],max=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    if(k>n)
    {
        cout<<max;
    }
    else
    {
    for(int i=0;i<n;i++)
    {

        for(int j=i+1;j<n;j++)
        {
            if(a[j]<a[i])
            {
                y++;
                if(y==k)
                {
                    z=a[i];
                    d=1;
                    break;
                }
                if(j==n-1)
                {
                     z=a[i];
                    f=1;
                    break;
                }

            }
            else
            {
                z=a[j];
                break;
            }
        }
        if(d==1 || f==1)
        {
            break;
        }

    }
    cout<<z;
    }

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int n,k,x=0,y=0,z=0,d=0,f=0;
    cin>>n>>k;
    ll int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
         x=a[i];
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<x)
            {
                y++;
                if(y==k)
                {
                    z=a[i];
                    d=1;
                    break;
                }
                if(j==n-1)
                {
                     z=a[i];
                    f=1;
                    break;
                }

            }
            else
            {
                z=a[j];
                break;
            }
        }
        if(d==1 || f==1)
        {
            break;
        }

    }
    cout<<z;

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
 int gcd(int a,int b)
 {
     if(b==0)
     {
         return a;
     }
     else
     {
         gcd(b,a%b);
     }
 }
int main()
{
    queue<int> q;
    int n;
    ll int k,x,y=1,a;
    cin>>n>>k;
    cin>>a;
    for(int i=1;i<n;i++)
    {
        cin>>x;
        if(y==k)
        {
            break;
        }
        if(a>x)
        {
            y++;
        }
        else
        {
            y=1;
            a=x;

        }

    }
    cout<<a<<endl;

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll int n,k,x=0,y=0,z=0,d=0,f=0;
    cin>>n>>k;
    ll int a[n],max=0;
    vector<ll int>v;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        v.push_back(a[i]);
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    if(k>n)
    {
        cout<<max;
    }
    else
    {
    for(int i=0;i<n;i++)
    {
        y=0;
        if(v[i]!=0)
        {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<a[i])
            {
                v.push_back(a[i]);
                y++;
                if(y==k)
                {
                    z=a[i];
                    d=1;
                    break;
                }
                if(j==n-1)
                {
                     z=a[i];
                    f=1;
                    break;
                }
                n++;
                v[i]=0;

            }
            else
            {
                z=a[j];
                break;
            }
        }
        if(d==1 || f==1)
        {
            break;
        }
        }

    }
    cout<<z;
    }

}


//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define ll long long
 int gcd(int a,int b)
 {
     if(b==0)
     {
         return a;
     }
     else
     {
         gcd(b,a%b);
     }
 }
int main()
{
    queue<int> q;
    int n;
    ll int k,x,y=0,a;
    cin>>n>>k;
    cin>>a;
    for(int i=1;i<n;i++)
    {
        cin>>x;
        if(y==k)
        {
            break;
        }
        if(a>x)
        {
            y++;
        }
        else
        {
            y=1;
            a=x;

        }

    }
    cout<<a<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int n, mx = 0, a[500], c[500] = {};
ll k;

int main() {
    fast;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        if (a[mx] < a[i]) mx = i;
        if (++c[mx] == k) {
            cout << mx << endl;
            return 0;
        }
    }
    cout << n << endl;;
    return 0;
}


#include <iostream>
#include <queue>
using namespace std;

int main() {
    long long k;
    int n,p[1000000],cur,amt;
    cin>>n;
    cin>>k;
    amt=0;
    cur=0;
    for (int x=0;x<n;x++){
        cin>>p[x];
        if (cur>p[x]){
            amt=amt+1;
            if (amt>=k){
                cout<<cur<<endl;
                return 0;
            }
        }
        else {
            if (x!=0){
                amt=1;
            }
            cur=p[x];
        }
    }
    cout<<cur<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, mx = 0, a[500], c[500] = {};
long long k;

int main() {
    fast;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        if (a[mx] < a[i]) mx = i;
        if (++c[mx] == k) {
            cout << mx << endl;
            return 0;
        }
    }
    cout << n << endl;;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, mx = 0, a[500], c[500] = {};
long long k;

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        if (a[mx] < a[i]) mx = i;
        if (++c[mx] == k) {
            cout << mx << endl;
            return 0;
        }
    }
    cout << n << endl;;
    return 0;
}


#include <bits/stdc++.h>
#define fori(i, st, en) for(int i = st; i < en; i++)
#define rfori(i, st, en) for(int i = st; i >= en; i--)
#define f first
#define s second
#define pb push_back
#define INF 0x3f3f3f3f
#define MAXN 100010
using namespace std;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;

int n, k, p[1010], wins[510];
deque<int> dq;

int main(){
	scanf("%d%d", &n, &k);
	int bpow = 0;
	fori(i, 0, n) {
		scanf("%d", p+i);
		bpow = max(bpow, p[i]);
		dq.push_back(p[i]);
		p[i+n] = p[i];
	}
	int f, s, cwins = 0;
	while(dq.front() != bpow){
		f = dq.front();
		dq.pop_front();
		s = dq.front();
		dq.pop_front();
		if(s < f) dq.push_back(s), dq.push_front(f), cwins++;
		else cwins = 1, dq.push_front(s), dq.push_back(f), swap(s, f);
		if(cwins >= k){
			cout << f << endl;
			return 0;
		}
	}
	cout << bpow << endl;
	return 0;
}


#include <bits/stdc++.h>
#define fori(i, st, en) for(int i = st; i < en; i++)
#define rfori(i, st, en) for(int i = st; i >= en; i--)
#define f first
#define s second
#define pb push_back
#define INF 0x3f3f3f3f
#define MAXN 100010
using namespace std;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;

int n, k, p[1010], wins[510];
deque<int> dq;

int main(){
	scanf("%d%d", &n, &k);
	int bpow = 0;
	fori(i, 0, n) {
		scanf("%d", p+i);
		bpow = max(bpow, p[i]);
		dq.push_back(p[i]);
		p[i+n] = p[i];
	}
	if(k > n){
		cout << bpow << "\n";
	}else{
		int f, s, cwins = 0;
		while(dq.front() != bpow){
			if(cwins >= k){
				cout << f << endl;
				return 0;
			}
			f = dq.front();
			dq.pop_front();
			s = dq.front();
			dq.pop_front();
			if(s < f) dq.push_back(s), dq.push_front(f), cwins++;
			else cwins = 0, dq.push_front(s), dq.push_back(f);
		}
		cout << bpow << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define fori(i, st, en) for(int i = st; i < en; i++)
#define rfori(i, st, en) for(int i = st; i >= en; i--)
#define f first
#define s second
#define pb push_back
#define INF 0x3f3f3f3f
#define MAXN 100010
using namespace std;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;

int n, k, p[1010], wins[510];

int main(){
	scanf("%d%d", &n, &k);
	int bpow = 0;
	fori(i, 0, n) {
		scanf("%d", p+i);
		bpow = max(bpow, p[i]);
		p[i+n] = p[i];
	}
	if(k > n){
		cout << bpow << "\n";
	}else{
		fori(i, 0, n){
			fori(j, 0, n){
				if(p[i+j+1] < p[i]) wins[i]++;
				else break;
			}
			if(wins[i] >= k){
				cout << p[i] << "\n";
				return 0;
			}
		}
		cout << bpow << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define fori(i, st, en) for(int i = st; i < en; i++)
#define rfori(i, st, en) for(int i = st; i >= en; i--)
#define f first
#define s second
#define pb push_back
#define INF 0x3f3f3f3f
#define MAXN 100010
using namespace std;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;

int n, k, p[1010], wins[510];
deque<int> dq;

int main(){
	scanf("%d%d", &n, &k);
	int bpow = 0;
	fori(i, 0, n) {
		scanf("%d", p+i);
		bpow = max(bpow, p[i]);
		dq.push_back(p[i]);
		p[i+n] = p[i];
	}
	int f, s, cwins = 0;
	while(dq.front() != bpow){
		f = dq.front();
		dq.pop_front();
		s = dq.front();
		dq.pop_front();
		if(s < f) dq.push_back(s), dq.push_front(f), cwins++;
		else cwins = 0, dq.push_front(s), dq.push_back(f);
		if(cwins >= k){
			cout << f << endl;
			return 0;
		}
	}
	cout << bpow << endl;
	return 0;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=0;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]>=d[j]){
       c++;
      } else {c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
      j++;
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=1;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]>d[j]){
       j++;c++;
      } else {c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int maim(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=1;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]<d[j]){
       j++;c++:
      } else c=0;
      if(c>=b){
       cout<<d[e];return 0;
      }
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=0;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]>d[j]){
       c++;
      } else if(d[e]!=d[j]){c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
      j++;
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=0;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]>d[j]){
       c++;
      } else if(d[e]!=d[j]){c=1;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
      j++;
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=1;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]<d[j]){
       j++;c++;
      } else {c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int maim(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=1;c=0;e=0;
   while(d[j]!=mix){
      if(d[e]<d[j]){
       j++;c++;
      } else {c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
   }
   cout<<mix;
}


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

long long a,b,c,d[501],j,mix,e;
int main(){
   cin>>a>>b;
   for(int i = 0; i < a; i++){
     cin>> d[i];
     mix=max(mix,d[i]);
   }
   j=1;c=0;e=0;
   while(d[e]!=mix){
      if(d[e]>d[j]){
       j++;c++;
      } else {c=0;e=j;}
      if(c>=b){
       cout<<d[e];return 0;
      }
   }
   cout<<mix;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k >= n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            for (int i = 1; i < n && s != k; ++i)
            {
                if (m[0] > m[i])
                    ++s;
                else
                {
                    m [0] = m[i];
                    s = 1;
                }
            }
            printf("%d", m[0]);
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k > n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            for (int i = 1; i < n && s != k; ++i)
            {
                if (m[0] > m[i])
                    ++s;
                else
                {
                    m [0] = m[i];
                    s = 1;
                }
            }
            printf("%d", m[0]);
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k > n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            int i = 1;
            while (s < k)
            {
                if (m[0] > m [i])
                {
                    ++s;
                } else
                    {
                        m[0] = m[i];
                        s = 1;
                    }
                ++i;
            }
            printf("%d", m[0]);
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k >= n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            int i = 1;
            while (s != k)
            {
                if (m[0] > m [i])
                {
                    ++s;
                } else
                    {
                        m[0] = m[i];
                        s = 1;
                    }
                ++i;
            }
            printf("%d", m[0]);
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k > n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            int i = 1;
            while (s != k)
            {
                if (m[0] > m [i])
                {
                    ++s;
                } else
                    {
                        m[0] = m[i];
                        s = 1;
                    }
                ++i;
            }
            printf("%d", m[0]);
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, k, s = 0, m[500];
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k >= n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            for (int i = 0; i < n; ++i)
            {
               for (int y = i+1; y <= i + k; ++y)
                {
                   if (m[i] > m[y])
                    ++s;
                   else
                   {
                       s = 0;
                       break;
                   }
                }
                if (s >=k )
                {
                    printf("%d", m[i]);
                    break;
                }
            }
        }
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, s = 0, m[500];
    long long k;
    scanf("%d %I64d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &m[i]);
    }
    if (k > n-1)
    {
        sort(m, m+n);
        printf("%d", m[n-1]);
    } else
        {
            for (int i = 1; i < n && s != k; ++i)
            {
                if (m[0] > m[i])
                    ++s;
                else
                {
                    m [0] = m[i];
                    s = 1;
                }
            }
            printf("%d", m[0]);
        }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	long long k;	//k最大是10的12次方，所以要用long long
	int n;
	while(cin >> n >> k){
		int a[510];
		for(int i = 0;i < n;i++)
			cin >> a[i];

		int j = 0,mark = 0,count = 0;
		while(true){
			int i = j + 1;
			while(1){
				if(count >= k || count >= n - 1){
					mark = 1;
					break;
				}

				if(i == n)	//超出数组时把 i 赋值成0，继续比较
					i = 0;

				if(a[j] > a[i]){	//a[j] > a[i] 交换位置，j 的值也要变成 i
					int t = a[j];
					a[j] = a[i];
					a[i] = t;
					j = i;
					count++;
				}
				else{	//a[j] < a[i]，j 赋值成 i 就行
					j = i;
					count = 1;	//初始化成 1 因为这时候已经赢了一次了
					break;
				}
				i++;
			}
			if(mark)
				break;
		}
		cout << a[j] << endl;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

// 32 42 4 46 76 2 3 45
/*
7 3
23 7 34 2 9 43 5
7 23 34
7 23 34 2
7 23 2 9 34 5 43

*/
int main(){
	long long n;
	long long k;
	while(cin >> n >> k){
		int b[1000],maxx;
		for(int i = 0;i < n;i++){
			cin >> b[i];
			if(maxx < b[i]){
				maxx  = b[i];
			}
		}
		if(k >= n){
			cout << maxx<<endl;
			continue;
		}
		int pos;
		int j = 0,mark = 0;
		long long c = 0;
		while(1){
			int i = j + 1;
			while(1){
				if(c >= k || c >= n + 1){
					mark = 1;
					pos = j;
					break;
				}
				if(i == n) i = 0;
				if(b[j] > b[i]){
					int t = b[j];
					b[j] = b[i];
					b[i] = t;
					c++;
					j = i;
				}
				else if(b[i] > b[j]){
					j = i;
					c = 1;
					break;
				}
				i = j+1;
			}
			if(mark){
				break;
			}
		}
		cout << b[pos]<< endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

// 32 42 4 46 76 2 3 45
/*
7 3
23 7 34 2 9 43 5
7 23 34
7 23 34 2
7 23 2 9 34 5 43

*/
int main(){
	long long n;
	long long k;
	while(cin >> n >> k){
		int b[1000],maxx;
		for(int i = 0;i < n;i++){
			cin >> b[i];
			if(maxx < b[i]){
				maxx  = b[i];
			}
		}
		if(k >= n){
			cout << maxx<<endl;
			continue;
		}
		int pos;
		int j = 0,mark = 0;
		long long c = 0;
		while(1){
			int i = j + 1;
			while(1){
				if(c >= k || c >= n - 1){
					mark = 1;
					pos = j;
					break;
				}
				if(i == n) i = 0;
				if(b[j] > b[i]){
					int t = b[j];
					b[j] = b[i];
					b[i] = t;
					c++;
					j = i;
				}
				else if(b[i] > b[j]){
					j = i;
					c = 1;
					break;
				}
				i = j+1;
			}
			if(mark){
				break;
			}
		}
		cout << b[pos]<< endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

// 32 42 4 46 76 2 3 45
/*
7 3
23 7 34 2 9 43 5
7 23 34
7 23 34 2
7 23 2 9 34 5 43

*/
int main(){
	long long k;
	int n;
	while(cin >> n >> k){
		int a[510];
		for(int i = 0;i < n;i++)
			cin >> a[i];

		int j = 0,mark = 0,c = 0;
		while(true){
			int i = j + 1;
			while(1){
				if(c >= k || c >= n + 1){
					mark = 1;
					break;
				}

				if(i == n)
					i = 0;

				if(a[j] > a[i]){
					int t = a[j];
					a[j] = a[i];
					a[i] = t;
					j = i;
					c++;
				}
				else{
					j = i;
					c = 1;
					break;
				}
				i++;
			}
			if(mark)
				break;
		}
		cout << a[j] << endl;
	}
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	long long k;
	int n;
	while(cin >> n >> k){
		int a[510];
		for(int i = 0;i < n;i++)
			cin >> a[i];

		int j = 0,mark = 0,count = 0;
		while(true){
			int i = j + 1;
			while(1){
				if(count >= k || count >= n + 1){
					mark = 1;
					break;
				}

				if(i == n)
					i = 0;

				if(a[j] > a[i]){
					int t = a[j];
					a[j] = a[i];
					a[i] = t;
					j = i;
					count++;
				}
				else{
					j = i;
					count = 1;
					break;
				}
				i++;
			}
			if(mark)
				break;
		}
		cout << a[j] << endl;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

// 32 42 4 46 76 2 3 45
/*
7 3
23 7 34 2 9 43 5
7 23 34
7 23 34 2
7 23 2 9 34 5 43

*/
int main(){
	long long n;
	long long k;
	while(cin >> n >> k){
		int b[1000],maxx;
		for(int i = 0;i < n;i++){
			cin >> b[i];
			if(maxx < b[i]){
				maxx  = b[i];
			}
		}
		if(k >= n){
			cout << maxx<<endl;
			continue;
		}
		int pos;
		int j = 0,mark = 0;
		while(1){
			int i = j + 1;
			long long c = 0;
			while(1){
				if(c >= k || c >= n + 1){
					mark = 1;
					pos = j;
					break;
				}
				if(i == n) i = 0;
				if(b[j] > b[i]){
					int t = b[j];
					b[j] = b[i];
					b[i] = t;
					c++;
					j = i;
				}
				else if(b[i] > b[j]){
					j = i;
					c = 0;
					break;
				}
				i = j+1;
			}
			if(mark){
				break;
			}
		}
		cout << b[pos]<< endl;
	}
}


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

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pir pair <int, int>
#define MK(x, y) make_pair(x, y)
#define MEM(x, b) memset(x, b, sizeof(x))
#define MPY(x, b) memcpy(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int Mod = 1e9 + 7;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
inline ll dpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % Mod; b >>= 1; t = (t*t) % Mod; }return r; }
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t); b >>= 1; t = (t*t); }return r; }

int a[510];

int main()
{
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		sc("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		int nxt = i % n + 1;
		ll cnt = 0;
		while (a[i] > a[nxt] && nxt != i) {
			cnt++;
			nxt = nxt % n + 1;
		}
		if (cnt >= k || cnt >= n - 1)
			printf("%d\n", a[i]), exit(0);
	}
	return 0;  // 改数组大小!!!用pair记得改宏定义!!!
}


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

#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pir pair <int, int>
#define MK(x, y) make_pair(x, y)
#define MEM(x, b) memset(x, b, sizeof(x))
#define MPY(x, b) memcpy(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))

typedef long long ll;
const int Mod = 1e9 + 7;
const int N = 2e5 + 100;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
inline ll dpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t) % Mod; b >>= 1; t = (t*t) % Mod; }return r; }
inline ll fpow(ll a, ll b){ ll r = 1, t = a; while (b){ if (b & 1)r = (r*t); b >>= 1; t = (t*t); }return r; }

int a[510];

int main()
{
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		sc("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		int nxt = i % n + 1;
		ll cnt = 0;
		while (a[i] > a[nxt] && nxt != i) {
			cnt++;
			nxt = nxt % n + 1;
		}
		if (cnt >= k || nxt == i)
			printf("%d\n", a[i]), exit(0);
	}
	return 0;  // 改数组大小!!!用pair记得改宏定义!!!
}


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        dp[i] = mp[a[i]-1] + 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp.reserve(1024);
    mp.max_load_factor(0.25);
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        dp[i] = mp[a[i]-1] + 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    int dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        auto it = mp.find(a[i]-1);
        if(it != mp.end())
            dp[i] = max(dp[i-1] , it->second + 1);
        else
            dp[i] = 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    deque<int> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
13
3 6 3 7 3 8 3 4 5 9 10 11 3
*/


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        dp[i] = mp[a[i]-1] + 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];//
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    int dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp[a[0]] = 1;

    for(int i=1; i<n; i++)
    {
        auto it = mp.find(a[i]-1);
        if(it != mp.end())
            dp[i] = max(dp[i-1] , it->second + 1);
        else
            dp[i] = 1;

        mp[a[i]] = dp[i];
    }
    vector<int> ans;
    int k=1;
    for(int i=0; i<n; i++){
        if(dp[i] == k){
            ans.push_back(i+1);
            k++;
        }
    }

    cout <<dp[n-1] << "\n";
    for(int i=0; i<ans.size(); i++){
        cout << ans[i] << " ";
    }

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        auto it = mp.find(a[i]-1);
        if(it != mp.end())
            dp[i] = it->second + 1;
        else
            dp[i] = 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    unordered_map<int,int> mp;
    mp.reserve(131072);
    mp.max_load_factor(0.25);
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        dp[i] = mp[a[i]-1] + 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


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

int main()
{
    int n;
    cin >> n;
    long long a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];

    long long dp[n];
    dp[0] = 1;
    map<int,int> mp;
    mp[a[0]] = 1;
    int maxI=0,maxNum=dp[0];

    for(int i=1; i<n; i++)
    {
        dp[i] = mp[a[i]-1] + 1;

        mp[a[i]] = dp[i];
        if(dp[i]>maxNum){
            maxI = i;
            maxNum = dp[i];
        }
    }
    // for(int i=0; i<n; i++)
    //     cout << dp[i] << " ";
    // cout << "\n" << dp[maxI];
    deque<long long> ans;
    int k = a[maxI];
    for(int i=maxI; i>=0 && k>a[maxI]-dp[maxI]; i--)
    {
        if(a[i]==k){
            ans.push_front(i+1);
            k--;
        }
    }
    cout << dp[maxI] << "\n";
    while(!ans.empty()){
        cout << ans.front()<<" ";
        ans.pop_front();
    }
    cout << "\n";

	return 0;
}
/*
12
3 6 7 8 3 3 4 5 9 10 11 9
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      {cin>>a[i];
      }
      ll len = 0;ll val;
    unordered_map<ll,pair<ll,vector<ll> > > dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1].first + 1>len)
               {
                     len = dp[a[i] - 1].first + 1;
                     val = a[i];
               }
               dp[a[i]].first = dp[a[i] - 1].first + 1;
               dp[a[i]].second = dp[a[i] - 1].second;
               dp[a[i]].second.push_back(i);
          }
          else
          {vector<ll> b;
          b.push_back(i);
          if(len<1)
          {len =1;
          val = a[i];}
          dp[a[i]] = {1,b};}

    }
    //cout<<val<<" ";
    cout<<len<<endl;
    for(ll i=0;i<dp[val].second.size();i++)
    cout<<dp[val].second[i] + 1<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      {cin>>a[i];
      }
      ll len = 1;ll val;
    unordered_map<ll,pair<ll,vector<ll> > > dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1].first + 1>len)
               {
                     len = dp[a[i] - 1].first + 1;
                     val = a[i];
               }
               dp[a[i]].first = dp[a[i] - 1].first + 1;
               dp[a[i]].second = dp[a[i] - 1].second;
               dp[a[i]].second.push_back(i);
          }
          else
          {vector<ll> b;
          b.push_back(i);
          dp[a[i]] = {1,b};}

    }
    cout<<len<<endl;
    for(ll i=0;i<dp[val].second.size();i++)
    cout<<dp[val].second[i] + 1<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      cin>>a[i];
      bool flag = true;
      for(ll i=1;i<n;i++)
      {
            if(a[i] - a[i-1]!=1)
            {
                  flag = false;
                  break;
            }
      }
      if(flag)
      {
            cout<<n<<endl;
            for(ll i=1;i<=n;i++)
            cout<<i<<" ";
            return 0;
      }
      ll len = 0;ll val; ll l;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;
          }
          else
          {if(len<1)
          {
                len = 1;
                val = a[i];
                l = i;
          }
          dp[a[i]] = 1;}

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];
      unordered_map<ll,ll> m;
      for(ll i=0;i<n;i++)
      {cin>>a[i];
      if(m.find(a[i]) == m.end())
      m[a[i]] = i;}
      ll len = 1;ll val;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
               }
               dp[a[i]] = dp[a[i] - 1] + 1;
          }
          else
          dp[a[i]] = 1;

    }
    cout<<len<<endl;
    for(ll i=val - len + 1;i<=val;i++)
    cout<<m[i]+1<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
       ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
      ll n;
      cin>>n;
      ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
      ll len = 0;ll val; ll l;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {   if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      {cin>>a[i];
      }
      ll len = 1;ll val;
    unordered_map<ll,pair<ll,vector<ll> > > dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1].first + 1>len)
               {
                     len = dp[a[i] - 1].first + 1;
                     val = a[i];
               }
               dp[a[i]].first = dp[a[i] - 1].first + 1;
               dp[a[i]].second = dp[a[i] - 1].second;
               dp[a[i]].second.push_back(i);
          }
          else
          {vector<ll> b;
          b.push_back(i);
          val = a[i];
          dp[a[i]] = {1,b};}

    }
    //cout<<val<<" ";
    cout<<len<<endl;
    for(ll i=0;i<dp[val].second.size();i++)
    cout<<dp[val].second[i] + 1<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
       ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
      ll n;
      cin>>n;
      ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
      ll len = 0;ll val; ll l;
map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {   if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
       ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      cin>>a[i];
      bool flag = true;
      for(ll i=1;i<n;i++)
      {
            if(a[i] - a[i-1]!=1)
            {
                  flag = false;
                  break;
            }
      }
      if(flag)
      {
            cout<<n<<endl;
            for(ll i=1;i<=n;i++)
            cout<<i<<" ";
            return 0;
      }
      ll len = 0;ll val; ll l;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;
          }
          else
          {if(len<1)
          {
                len = 1;
                val = a[i];
                l = i;
          }
          dp[a[i]] = 1;}

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];
      unordered_map<ll,ll> m;
      for(ll i=0;i<n;i++)
      {cin>>a[i];
      if(m.find(a[i]) == m.end())
      m[a[i]] = i;}
      ll len = 0;ll val; ll l;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;
          }
          else
          {if(len<1)
          {
                len = 1;
                val = a[i];
                l = i;
          }
          dp[a[i]] = 1;}

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
 {
      ll n;
      cin>>n;
      ll a[n];

      for(ll i=0;i<n;i++)
      cin>>a[i];

      ll len = 0;ll val; ll l;
    unordered_map<ll,ll> dp;
    for(ll i=0;i<n;i++)
    {
          if(dp.find(a[i] -1)!=dp.end())
          {
               if(dp[a[i] - 1] + 1>len)
               {
                     len = dp[a[i] - 1] + 1;
                     val = a[i];
                     l = i;
               }
               dp[a[i]] = dp[a[i] - 1] + 1;
          }
          else
          {if(len<1)
          {
                len = 1;
                val = a[i];
                l = i;
          }
          dp[a[i]] = 1;}

    }
    cout<<len<<endl;
    vector<ll> ans;

    for(ll i=l;i>=0 && len>0;i--)
    {
          if(a[i] == val)
          {
                ans.push_back(i+1);
                val--;
                len--;
          }
    }
    reverse(ans.begin(),ans.end());
    for(ll i=0;i<ans.size();i++)
    cout<<ans[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

umll dp;
ll ans,last,x,val;
vll a;

int main()
{
	fastIO
	ll n;
	cin>>n;

	rep(i,0,n-1,1)
	{

		cin>>x;
		a.pb(x);
		dp[x]=dp[x-1]+1;
	//	parent[i]=pos[a[i]-1];
		//pos[a[i]]=i;
		if(dp[x]>ans)
		{
			last=x;
			ans=dp[x];
		}
	}
	cout<<ans<<"\n";
	val=last-ans+1;
//	db(last,a[last]);
	rep(i,0,n-1,1)
	if(a[i]==val)
	{
	cout<<i+1<<" ";
	val++;
	if(val>last)
	return 0;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

int main()
{
	fastIO
	ll n;
	cin>>n;
	vll a(n);
	input(a,n);
	um<ll,ll> dp;
	umll idx,parent,pos;
	pll p;
	ll ans=0,last;
	rep(i,0,n-1,1)
	{
		dp[a[i]]=dp[a[i]-1]+1;
		parent[i]=pos[a[i]-1];
	//	db(parent[i],i);
		pos[a[i]]=i;
		if(dp[a[i]]>ans)
		{
			last=i;
			ans=dp[a[i]];
		}
	}
	cout<<ans<<"\n";
	vll v;
	rep(i,0,ans-1,1)
	{
	v.pb(last+1);
	last=parent[last];
	}
	reverse(all(v));
	show(v,v.size());
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

int main()
{
	fastIO
	ll n;
	cin>>n;
	vll a(n);
	input(a,n);
	map<ll,ll> dp;
	mll idx,parent,pos;
	pll p;
	ll ans=0,last;
	rep(i,0,n-1,1)
	{
		dp[a[i]]=dp[a[i]-1]+1;
		parent[i]=pos[a[i]-1];
	//	db(parent[i],i);
		pos[a[i]]=i;
		if(dp[a[i]]>ans)
		{
			last=i;
			ans=dp[a[i]];
		}
	}
	cout<<ans<<"\n";
	vll v;
	rep(i,0,ans-1,1)
	{
	v.pb(last+1);
	last=parent[last];
	}
	reverse(all(v));
	show(v,v.size());
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

int main()
{
	fastIO
	ll n;
	cin>>n;
	vll a(n);
	input(a,n);
	um<ll,ll> dp;
	ll ans=0,last;
	rep(i,0,n-1,1)
	{
		dp[a[i]]=dp[a[i]-1]+1;
	//	parent[i]=pos[a[i]-1];
		//pos[a[i]]=i;
		if(dp[a[i]]>ans)
		{
			last=i;
			ans=dp[a[i]];
		}
	}
	cout<<ans<<"\n";
	ll val=a[last]-ans+1;
	rep(i,0,n-1,1)
	if(a[i]==val)
	{
	cout<<i+1<<" ";
	val++;
	if(val==a[last])
	break;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

ll poww(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD) { return powm(a, m-2, m);}

int main()
{
	fastIO
	ll n;
	cin>>n;
	vll a(n);
	input(a,n);
	um<ll,ll> dp;
	umll pos;
	vll parent(n);
	pll p;
	ll ans=0,last;
	rep(i,0,n-1,1)
	{
		dp[a[i]]=dp[a[i]-1]+1;
		parent[i]=pos[a[i]-1];
		pos[a[i]]=i;
		if(dp[a[i]]>ans)
		{
			last=i;
			ans=dp[a[i]];
		}
	}
	cout<<ans<<"\n";

	vll v;
	rep(i,0,ans-1,1)
	{
	v.pb(last+1);
	last=parent[last];
	}
	repb(i,(ll)v.size()-1,0,1)
	cout<<v[i]<<" ";
	return 0;
}