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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;

class Program
{
    const int MOD = 1000000007;
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int n = cin.NextInt();
        int k = cin.NextInt();

        int possibleMax = (n - 1) * (n - 2) / 2;
        
        // impossible case
        if (possibleMax < k)
        {
            Console.WriteLine(-1);
            return;
        }

        List<Tuple<int, int>> pairOfVertexes = new List<Tuple<int, int>>();


        // nから残りの辺へのスターグラフを作る
        for (int i = 1; i < n-1; i++)
        {
            pairOfVertexes.Add(Tuple.Create(i, n));
        }


        // 作成されたスターグラフから最短距離2となる頂点ペアを削除
        // [1, n-1]のペアを繋ぐことで候補から削除できる
        int rem = possibleMax - k;
        int vertex1 = 1;
        int vertex2 = 2;        
        for (int i = 0; i < rem; i++)
        {
            pairOfVertexes.Add(Tuple.Create(vertex1, vertex2));

            // next candidate to connect.
            vertex2++;

            // vertex1と組み合わせるvertex2がnまで至った場合は
            // 次のvertex1からスタート
            if (vertex2 == n)
            {
                vertex1++;
                vertex2 = vertex1 + 1;
            }
        }


        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        foreach (var pair in pairOfVertexes)
        {
            Console.WriteLine("{0} {1}", pair.Item1, pair.Item2);
        }
        Console.Out.Flush();
    }

    long CountUnCovered(long lowerBound, long divisor)
    {
        if (lowerBound % divisor == 0)
        {
            return lowerBound / divisor - 1;
        }
        return lowerBound / divisor;
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}