#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b,
               long long p = (long long)(1000000007)) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (long long)(1000000007)) {
  return (a % p + b % p) % p;
}
void solve() {
  long long n, k, mx = -1 * LLONG_MAX;
  cin >> n >> k;
  queue<long long> q;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    mx = max(mx, x);
    q.emplace(x);
  }
  if (k >= n - 1) {
    cout << mx << "\n";
    return;
  }
  long long res = q.front();
  q.pop();
  long long val = k;
  while (k != 0) {
    long long temp = q.front();
    q.pop();
    if (res > temp) {
      k--;
      q.emplace(temp);
    } else if (res < temp) {
      k = val - 1;
      q.emplace(res);
      res = temp;
    }
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
