#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> ve(n);
  map<long long int, long long int> mp;
  long long int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> ve[i];
    mx = max(mx, ve[i]);
  }
  long long int a = n, dem = 0, dem1 = 0;
  while (n-- > 0) {
    for (int i = 0; i < a; i++) {
      if (ve[i] > ve[i + 1]) {
        mp[ve[i]]++;
        if (mp[ve[i]] == m) {
          cout << ve[i] << "\n";
          return 0;
        }
        ve.insert(ve.end(), ve[i + 1]);
        ve.erase(ve.begin() + i + 1);
      } else {
        mp[ve[i + 1]]++;
        if (mp[ve[i + 1]] == m) {
          cout << ve[i + 1] << "\n";
          return 0;
        }
        ve.insert(ve.end(), ve[i]);
        ve.erase(ve.begin() + i);
      }
      break;
    }
  }
  cout << mx << "\n";
  return 0;
}
