#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>
//#include<atcoder/dsu>


//using namespace atcoder;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;



void solve() {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
        for (int i = 0; i < n; ++i) {
            cout << 2 * i + 1 << " " << 2 * i + 2 << "\n";
        }
        return;
    }
    if ((m < 0) || (m >= n - 1)) {
        cout << -1 << endl;
        return;
    }
    for (int i = 0; i < m + 1; ++i) {
        cout << 2 * i + 2 << " " << 2 * i + 3 << "\n";
    }
    cout << 1 << " " << 2 * m + 4 << "\n";
    int x = 2 * m + 4;
    for (int i = m + 2; i < n; ++i) {
        int j = i - m - 2;
        cout << x + 2 * j + 1 << " " << x + 2 * j + 2 << "\n";
    }



    
}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

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

typedef long long int ll;
using ii= pair<ll,ll>;
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001
#define mod 1000000007

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

auto start_time= high_resolution_clock::now();
void time()
{
    #ifndef ONLINE_JUDGE
        auto stop_time= high_resolution_clock::now();
        auto duration= duration_cast<milliseconds>(stop_time-start_time);
        cout<<"run time: "<<duration.count()<<" ms"<<"\n";
    #endif
    return;
}

void ojudge()
{
	#ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    return;
}

vector<ll> le,ri;
ll t=0;


void all_poss_subset_sum(vector<ll> & brr,vector<ll> &sum_vec)
{
	ll n = brr.size();
	ll no_of_subsets = (1<<n);
	

	fr(i,0,no_of_subsets){
		ll ans=0;
		fr(j,0,n){
			if(i & (1<<j)) ans += brr[j];
		}
		sum_vec.PB(ans);
	}
}


void meet_in_the_middle(ll arr[],ll n)
{
	
    vector<ll> left,right;

    fr(i,0,n/2) left.PB(arr[i]);
    fr(i,n/2,n) right.PB(arr[i]);

	all_poss_subset_sum(left,le);
	all_poss_subset_sum(right,ri);

	
	//return ans;
}

int main()
{
    ojudge();
    
    ll n;
    cin>>n>>t;

    ll arr[n];
    fr(i,0,n) cin>>arr[i];

    meet_in_the_middle(arr,n);
    
    sort(all(ri));
	ll ans=0;

	for(auto it:le)
	{
		if(it>t) continue;
        ll tgt = t-it;
		ll ind =   upper_bound( ri.begin(),ri.end(),tgt)-ri.begin()-1;

		ans = max(ans,it + ri[ind]);
	}


	cout<<ans<<"\n";

    time();
    return 0;
}
