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: Runtime Error)

#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

void check(vector<vector<int> > G, int K){
  int N = G.size();

  function<int(int,int,int,int)> dfs=[&](int pos, int pre, int dis, int start){
    if(dis > 2) return 0;
    if(dis == 2) return (int)(start < pos);
    int res = 0;
    for(int to:G[pos]){
      if(to == pre) continue;
      res += dfs(to, pos, dis + 1, start);
    }
    return res;
  };
  
  int ans = 0;
  for(int i=0;i<N;i++) ans += dfs(i, -1, 0, i);
  //for(int i=0;i<N;i++) pr(i, dfs(i, -1, 0, i));
  pr(ans);
  assert(ans == K);
}



int N;
int calc(int n){return (1 + n) * n / 2;}

_int mem[101][10000], used[101][10000];
int dfs(int idx, int cnt){
  //pr(idx, cnt);
  if(idx > N) return 0;
  if(cnt == 0) return idx == N;
  if(cnt < 0) return 0;
  if(idx >= N) return 0;
  if(used[idx][cnt]++) return mem[idx][cnt];
  
  int res = 0;
  for(int i=1;i<N;i++){
    res |= dfs(idx + i, cnt - calc(i));
  }
  return mem[idx][cnt] = res;
}

vector<vector<int> > G;
void dfs2(int idx, int cnt){
  //pr(idx, cnt);
  
  if(cnt == 0) return;

  for(int i=1;i<=N;i++){
    int f = dfs(idx + i, cnt - calc(i));
    if(f == 0) continue;
    for(int j=0;j<i;j++) G[idx-1].push_back(idx + j), G[idx + j].push_back(idx-1);
    dfs2(idx + i, cnt - calc(i));
    break;
  }  
}


vector<vector<int> > solve(int N, int K){
  vector<vector<int> > G(N);
  G[0].push_back(1);
  G[1].push_back(0);
  int root = 0;
  int node = 2;

  vector<int> last;
  while(K){
    last.clear();
    last.push_back(root);

    int t = node;
    for(int i=1;K - i >= 0;i++){
      K -= i;
      G[root].push_back(node);
      G[node].push_back(root);
      last.push_back(node);
      for(int j=0;j<t;j++)
	if(j != root) G[node].push_back(j), G[j].push_back(node);
      node++;
    }
    if(node > N) return {};
    root++;
  }

  while(node < N){
    for(int i=0;i<node;i++){
      G[i].push_back(node);
      G[node].push_back(i);
    }
    node++;
  }
  return G;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int K;
  cin>>N>>K;

  auto G = solve(N, K);

  if(G.empty()){
    cout<<-1<<endl;
    return 0;
  }

  int M = 0;
  for(int i=0;i<N;i++) M += G[i].size();
  M /= 2;

  
  cout<<M<<endl;
  for(int i=0;i<N;i++)
    for(int to:G[i]) if(i < to) cout<<i+1<<" "<<to+1<<endl;

  //check(G, K);
  return 0;
}