#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>

#include <fstream>


using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll n,m;cin>>n>>m;
    ll a[n];
    vector<ll> v[n];
    rep(i,0,n-1)v[i].pb(-1);
    rep(i,0,n-1){
        cin>>a[i];
        v[a[i]].pb(i);
    }
    rep(i,0,n-1)v[i].pb(n);
    rep(i,0,n-1){
        rep(j,0,(ll)v[i].size()-2){
            ll a=v[i][j];
            ll b=v[i][j+1];
            if(b-a>m){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<n<<endl;
    
    return 0;
    
}






#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x){
	x=0;bool dp=false;char ch=getchar();
	while(!isdigit(ch)){dp|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=dp?-x:x;
	return ;
} 
template<typename T>
inline void write(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10^48);
	return ;
}
const int N=2e5+5,INF=1e9+7;
#define ll long long
int n,m;
int main(){
	read(n),read(m);
	if(m==0){
		for(int i=1;i<=n;i++) printf("%d %d\n",i*2-1,i*2);
		return 0;
	}
	if(m<0 || m>n-2){
		puts("-1");
		return 0;
	}
	printf("1 %d\n",1<<25);int tot=2;
	for(int i=2;i<=m+2;i++,tot++) printf("%d %d\n",i*2-1,i*2);
	for(;tot<=n;tot++)printf("%d %d\n",(1<<25)+tot*2-1,(1<<25)+tot*2);
}