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

////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
//#define mod 9999991
long mod=9999991;
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
    double x=(double )a.first/a.second;
    double y=(double )b.first/b.second;
    return x<y;}
long Pow(long x, long y) {
    if(y == 0)return 1;
    long res=Pow(x,y/2)%mod;
    res=(res*res)%mod;
    if(y&1)res=(res*x)%mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long t,n,m,f=0,ans,a,b;
long tmp;



int main() {
///<editor-fold desc="ios">
    IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in=1,o;
    cin>>n>>m;
    vector<vector<int>> idx(n+1,{0});
    for(int i = 1; i <=n ; ++i){
        cin>>tmp;
        idx[tmp].push_back(i);
    }
    for(int i = 0; i <=n ; ++i){
        idx[i].push_back(n+1);
    }
    for(int i = 0; i <= n; ++i){
        for(int j = 1; j <idx[i].size() ; ++j){
            if(idx[i][j]-idx[i][j-1]-1>=m){
                cout<<i<<endl;
                return 0;
            }
        }
    }







}
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/rational.hpp>

// using bigint = boost::multiprecision::cpp_int;
// using fraction = boost::rational<bigint>;
using namespace std;

#define pb push_back
#define eb emplace_back
#define unused [[maybe_unused]]
#define tempT template<class T>
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl
#define ans_exit(x) { cout << x << endl; exit(0); }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++)

using ll   unused = long long;
using ld   unused = long double;
using vl   unused = vector<ll>;
using vvl  unused = vector<vl>;
using vvvl unused = vector<vvl>;
using lp   unused = pair<ll, ll>;
using lmap unused = map<int, int>;

unused constexpr ll MOD = 998244353;
unused constexpr ll INF = 1 << 30;
unused constexpr ll LINF = 1LL << 62;
unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1};
unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1};
unused inline bool bit(ll b, ll i) { return b & (1LL << i); }
unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; }
unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); }
unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); }
tempT unused inline bool in_range(T a, T x, T b) { return a <= x && x < b; }
unused inline bool in_range(ll x, ll b) { return in_range(0LL, x, b); }
tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; }
tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; }

int main() {
    ll n, m;
    cin >> n >> m;
    if(m < 0) ans_exit(-1);

    ll cnt = 0;
    vector<lp> ans;

    if(m != 0) {
        ans.pb({++cnt, -1});
        rep(i, m+1) {
            ans.pb({++cnt, 0});
            ans.back().second = ++cnt;
        }
        ans[0].second = ++cnt;
    }

    if(n < ans.size()) ans_exit(-1);

    while(ans.size() < n) {
        ans.pb({++cnt, 0});
        ans.back().second = ++cnt;
    }

    rep(i, n) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}