using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var N = line[0];
            var K = line[1];
            var max = (N - 1) * (N - 2) / 2;
            if (K > max) return -1;

            var edges = new List<Edge>(N * (N - 1) / 2);
            for (int i = N - 2; i >= 0; i--)
            {
                for (int j = i + 1; j < N; j++)
                {
                    edges.Add(new Edge { from = i, to = j });
                }
            }

            var res = edges.Skip(K).ToArray();

            Console.WriteLine(res.Length);
            return AllLines(res.Select(e => e.ToString()));
        }
        struct Edge
        {
            public int from;
            public int to;
            public override string ToString() => $"{from + 1} {to + 1}";
        }

        class GraphBuilder
        {
            private List<int>[] lists;
            public GraphBuilder(int count)
            {
                this.lists = new List<int>[count];
                for (int i = 0; i < count; i++)
                    this.lists[i] = new List<int>();
            }
            public GraphBuilder(int count, IEnumerable<int[]> arrays)
            {
                this.lists = new List<int>[count];
                for (int i = 0; i < lists.Length; i++)
                    this.lists[i] = new List<int>();
                foreach (var item in arrays)
                    this.Add(item[0], item[1]);
            }
            public void Add(int from, int to)
            {
                this.lists[from].Add(to);
                this.lists[to].Add(from);
            }
            public int[][] ToArray()
            {
                var N = this.lists.Length;
                var res = new int[N][];
                for (int i = 0; i < N; i++)
                    res[i] = this.lists[i].ToArray();
                return res;
            }
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> SplitString { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 13396