/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
int n,m;
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
signed main()
{
	n=read();m=read();
	if (n==1&&m==0)
	{
		printf("1 2\n");
		return 0;
	}
	if (m>=n-1||m<0)
	{
		printf("-1\n");
		return 0;
	}
	printf("1 100000000\n");m++;
	for (int i=1;i<m;i++) printf("%d %d\n",2*i,2*i+1);
	printf("%d %d\n",2*m,m+n);
	for (int i=m+1;i<n;i++) printf("%d %d\n",m+i,n+i);
}
#include <bits/stdc++.h>

using namespace std;


void setup() {
    #ifdef LOCAL
    freopen("input", "r", stdin);
    #else
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    #endif
}

#define int long long
vector<int> getTimes(vector<int> &a, int start, int end) {
    const int n = end - start;
    const int total = 1 << n;
    vector<int> times;
    for (int i = 0; i < total; i++) {
        int timeTook = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                timeTook += a[start + j];
            }
        }
        times.push_back(timeTook);
    }
    return times;
}


signed main() {
    setup();
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int &it : a) cin >> it;

    vector<int> times1 = getTimes(a, 0, n / 2), times2 = getTimes(a, n / 2, n);
    sort(times1.begin(), times1.end());
    sort(times2.begin(), times2.end());
    int r = times2.size() - 1;
    int best = 0;
    for (int i = 0; i < (int)times1.size(); i++) {
        while (r >= 0 && times1[i] + times2[r] > t) {
            r--;
        }
        if (r >= 0) {
            best = max(best, times1[i] + times2[r]);
        } else {
            break;
        }
    }
    cout << best << endl;
}