Problem:
Score: 500 points

Problem Statement

Does there exist an undirected graph with N vertices satisfying the following conditions?

The graph is simple and connected.

The vertices are numbered 1, 2, ..., N.

Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M, the length of each edge is 1, and Edge i connects Vertex u_i and Vertex v_i.

There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2.

If there exists such a graph, construct an example.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq K \leq \frac{N(N - 1)}{2}

Input

Input is given from Standard Input in the following format:

N K

Output

If there does not exist an undirected graph with N vertices satisfying the conditions, print -1.

If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):

M
u_1 v_1
:
u_M v_M

If there exist multiple graphs satisfying the conditions, any of them will be accepted.

Sample Input 1

5 3

Sample Output 1

5
4 3
1 2
3 1
4 5
2 3

This graph has three pairs of vertices such that the shortest distance between them is 2: (1,\ 4), (2,\ 4), and (3,\ 5). Thus, the condition is satisfied.

Sample Input 2

5 8

Sample Output 2

-1

There is no graph satisfying the conditions.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll,ll> MPll;
typedef set<ll> setl;

const ll INF = 1ll << 60;
const ld EPS = 1e-10;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll MOD = 1000000007;

//for文
#define FOR(i,a,b) for(ll i = (ll)a;i < (ll)b;i++)
#define FORE(i,a,b) for(ll i = (ll) a;i <= (ll) b;i++ )
#define REP(i,size)  for(ll i =(ll)0;i<size;i++)
#define REPE(i,size)  for(ll i =(ll)0;i<=size;i++)
#define REPR(i,size)  for(ll i =(ll)size;i>=0;i--)
#define FOREACH(it, vec) for (auto it = vec.begin(); it != vec.end(); it++)

//ソート
#define ALL(vec) (vec).begin(),(vec).end()
#define SORT(vec) sort(ALL(vec))
#define SORTA(arr) sort(arr,arr + (sizeof(arr) / sizeof(ll)))
#define INVSORT(vec) sort((vec).rbegin(),(vec).rend())
#define REV(vec) reverse(ALL(vec))
#define REVA(arr) reverse(arr,arr + (sizeof(arr) / sizeof(ll)))
#define INVSORTA(arr) sort(arr,arr + (sizeof(arr) / sizeof(ll))),REVA(arr)

//最大値最小値
#define MAX(vec) *max_element(ALL(vec))
#define UNIQ(vec) SORT(vec);vec.erase(unique(ALL(vec)),vec.end())
#define MIN(vec) *min_element(ALL(vec))

//出力
#define printl(a) cout << a << "\n"
#define print(a) cout << a
#define OUT(a) printf("%lld\n",a)
#define OUTA(array) REP(i,sizeof(array)/sizeof(ll)) printf("%lld\n",array[i])
#define OUTV(vec) REP(i,vec.size()) printf("%lld\n",vec[i])
#define SP printf(" ")

//入力
#define IN(x) scanf("%lld",&x)
#define INV(vec) REP(i,vec.size()) scanf("%lld",&vec[i])
#define INA(array) REP(i,sizeof(array)/sizeof(ll)) scanf("%lld",array + i)
#define INS(x) cin >> x
#define INCH(x) scanf(" %c",&x)

//型
#define P pair
#define vp vector<P>
#define F first
#define Ssum second

//その他
#define PB push_back
#define MP make_pair
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define INFI(a) memset(a,INF,sizeof(a))
#define MEM(a,b) memset(a,(b),sizeof(a))

//関数
template<class T> inline void amax(T &a,const T &b) { if(a < b) a = b; }
template<class T> inline void amin(T &a, const T &b) { if(a > b) a = b; }
/*
struct structure{
    ll num1,num2,string s;
    bool operator<(const rest &another) const{
        return this->s < another.s;
    }
    structure(ll a,ll b,string s){
        this->num1 = a,this->num2=b,this->s=s;
    }
};a
*/
//特殊
//#define int ll
#define _CRT_SECURE_NO_WARNINGS



/*
template <typename T>
struct UnionFindTree{

    vector<T> par;
    vector<T> num;

    UnionFindTree(T n) : par(n+1),num(n+1,1ll){
        for (int i = 1; i <= n; ++i) {
            par[i] = i;
            num[i] = 1;
        }
    }

    T root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }

    void unite(T x,T y){
        x = root(x);
        y = root(y);
        if(!same(x,y)) {
            if(num[x] < num[y]) swap(x,y);
            par[y] = x;
            num[x] += num[y];
            num[y] = 0;
        }
    }

    T same(T x,T y){
        return root(x) == root(y);
    }

    T maxnodes(){
        return MAX(num);
    }

};
 */


#define DEBUG

#ifdef DEBUG
#define debugl(x) cerr << #x << ":" << x<<"\n"
#define debug(x)  cerr << #x<<":"<<x<<endl;
#define  debugV(V) REP(iiiii,V.size()){cerr << iiiii << ":" << V[iiiii]<<endl;}
#define  debugA(A) REP(iiiiiii,sizeof(A)/sizeof(ll)){cerr << iiiiiii << ":" << V[iiiiiii]<<endl;}
#define  debugVV(V) REP(i123,V[0].size()){cerr << endl;REP(i1234,V.size()){cerr << V[i1234][i123];}}

#else
#define debug(x)
#define debugV(x)
#define debugA(x)
#define debugl(x)
#endif

#define ZERO(a) memset(a,0,sizeof(a))
#define ALL(vec) (vec).begin(),(vec).end()
#define SORT(vec) sort(ALL(vec))
ll  gcd(unsigned a, unsigned b) {
    if(a < b) return gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}


ll binary(ll key,vec &a){
    ll ok = a.size();ll dame = -1;
    while(abs(ok - dame) > 1){
        ll mid = (ok + dame) /2;
        if(a[mid] <= key) ok = mid;
        else dame = mid;
    }

    return ok;
}


ll n;
ll m;
ll k;
ll l;
ll temp;
ll x,y;
ll H,W;
char c;
ll ddy,ddx;

ll solve(ll A,ll C,ll D){
    ll q;
    ll p = A / C;
    q = A/ D;
    ll r = A / (C*D/gcd(C,D));
    return p+q-r;
}

signed main() {
    IN(n);
    IN(k);
    vec node(n);
    vector<P<ll,ll>> edge;
    edge.PB(MP(1,2));
    edge.PB(MP(2,3));
    deque<ll>  haji;
    haji.PB(1);
    haji.PB(3);
    deque<ll>  node2;
    node2.PB(2);
    deque<ll> node3;
    ll temp = 1;
    ll cuno;
    FOR(i,4,n+1){
        if(k > temp + 3){
            if(!node3.empty()){
                cuno = node3.front();
                node3.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                temp += 3;
            }else if(!node2.empty()){
                cuno = node2.front();
                node2.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                node3.PB(cuno);
                temp += 3;
            }else if(!haji.empty()){
                cuno = haji.front();
                haji.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                node2.PB(cuno);
                temp += 1;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }else if(k  ==  temp + 3){
            if(k > temp + 3 and i == n) {
                if (!node3.empty()) {
                    cuno = node3.front();
                    node3.pop_front();
                    edge.PB(MP(cuno, i));
                    haji.PB(i);
                    temp += 3;
                    break;
                } else if (!node2.empty()) {
                    cuno = node2.front();
                    node2.pop_front();
                    edge.PB(MP(cuno, i));
                    haji.PB(i);
                    node3.PB(cuno);
                    temp += 3;
                } else if (!haji.empty()) {
                    cuno = haji.front();
                    haji.pop_front();
                    edge.PB(MP(cuno, i));
                    haji.PB(i);
                    node2.PB(cuno);
                    temp += 1;
                } else {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }else if(k == temp + 2){
            if(!node2.empty() and i == n){
                cuno = node2.front();
                node2.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                node3.PB(cuno);
                temp += 2;
                break;
            }else if(!haji.empty()){
                cuno = haji.front();
                haji.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                node2.PB(cuno);
                temp += 1;
            }else{
                cout << -1 << endl;
                return 0;
            }

        }else if(k == temp + 1 ){
            if(!haji.empty() and i == n){
                cuno = haji.front();
                haji.pop_front();
                edge.PB(MP(cuno,i));
                haji.PB(i);
                node2.PB(cuno);
                temp += 1;
                break;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    if(temp == k) {
        OUT(edge.size());
        FOR(i, 0, edge.size()) {
            cout << edge[i].first << " " << edge[i].second << endl;
        }
    }else{
        cout << -1 << endl;
    }
}