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<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
using pii = pair<int, int>;
using vi = vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0


bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second < b.second;
}


int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    
    
    
    
    
    
    int n, k; cin >> n >> k;
    /*
    if (k > n * (n - 1) / 2) { //存在し得ないペア
        cout << -1 << endl;
        return 0;
    }
    if (k == n - 2) {
        cout << n - 1 << endl;
        rep3(i, 1, n) {
            cout << i << " " << i + 1 << endl;
        }
        return 0;
    }
    if (k == n) {
        cout << n << endl;
        rep3(i, 1, n) {
            cout << i << " " << i + 1 << endl;
            
        }
        cout << n << " " << 1 << endl;
        return 0;
    }
    if (k == (n - 1) * (n - 2) / 2) {
        cout << n - 1 << endl;
        rep3(i, 2, n + 1) {
            cout << 1 << " " << i << endl;
        }
        return 0;
    }
     */
    /*
    if (k == ((n - 2) - 1) * 2) { //完全グラフの1頂点から2本
        cout << 1 << " " << 2 << endl;
        cout << 1 << " " << 3 << endl;
        
    }
     */
    vector<pii> v;
    rep3(i, 1, n) {
        rep3(j, i + 1, n + 1) {
            v.eb(i, j);
        }
    }
    //cout << SZ(v) << endl;
    //rep(i, SZ(v)) cout << v[i].F << " " << v[i].S << endl;
    cout << SZ(v) - k << endl;
    rep(i, SZ(v) - k) {
        cout << v[i].F << " " << v[i].S << endl;
       
        
    }
}
//cast caution