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);

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

}


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;
    }
}



Measured memory_bytes: 13268