#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	if(n==1&&m==0)
	{
		printf("1 2\n");
		return 0;
	}
	if(m<0||m>=n-1)
	{
		printf("-1\n");
		return 0;
	}
	m++;
	printf("1 %d\n",2*m+2);
	for(int i=1;i<=m;i++)
		printf("%d %d\n",i*2,i*2+1);
	for(int i=m+1;i<n;i++)
		printf("%d %d\n",i*2+1,i*2+2);
	return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define int long long

int N,L;
vector<int> A(1e5+10), B(1e5+10), C, high(1e5+10), low(1e5+10);

main() {

    cin >> N >> L;
    C.push_back(0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        C.push_back(A[i]-i);
    }
    C.push_back(L-N);
    
    int t = 0;
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
      //  cout << "Goal: " << " " << B[i] << "\n";
      //  for (int c: C) cout << c+i << " "; cout << "\n";
        auto it = lower_bound(C.begin(), C.end(), B[i]-i);
        if (it == C.end() || *it != B[i]-i) {
            cout << "-1\n";
            return 0;
        }
        auto it2 = upper_bound(C.begin(), C.end(), B[i]-i);
        int z = it-C.begin();
        int z2 = it2-C.begin()-1;
        if (z <= i && i <= z2) {
            z = i;
        }
        else if (abs(z2-i) < abs(z-i)) {
            z = z2;
        }
        //go from i to z
        //cout << i << " to " << z << "\n";
        if (i < z) {
            low[z] = max(z-i, low[z]);
        }
        if (i > z) {
            high[z] = max(i-z,high[z]);
        }
    }

    for (int i = 0; i <= N+1; i++) {
       // cout << i << " " << low[i] << " " << high[i] << "\n";
        t += low[i] + high[i];
    }

    cout << t << "\n";

   // cout << t << "\n";



    return 0;
}