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 (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import random
import collections
import math
import itertools
import bisect

def real_main():
    n, k = read_int_array()
    max_pairs = (n - 2) * (n - 1) // 2
    if k > max_pairs:
        print(-1)
        return

    cur_pairs = max_pairs
    edges = []
    for i in range(1, n):
        edges.append([1, i+1])
    cur_node = 1
    last = [i for i in range(n)]
    for _ in range(cur_pairs - k):
        if last[cur_node] == n-1:
            cur_node += 1
        last[cur_node] += 1
        edges.append([cur_node + 1, last[cur_node] + 1])
    print(len(edges))
    print('\n'.join(str(e[0]) + ' ' + str(e[1]) for e in edges))


def solve():
    pass


def main():
    if False and 'PYCHARM_HOSTED' in os.environ:
        main_pycharm()
    else:
        real_main()


from copy import deepcopy
def main_pycharm():
    solution = solve

    test_inputs = None
    test_outputs = None
    judge = None
    slow_solution = None
    if solution is not None:
        if test_outputs is not None:
            test_with_answers(solution, test_inputs, test_outputs)
        if judge is not None:
            test_with_judge(solution, test_inputs, judge)
        if slow_solution is not None:
            test_with_slow_solution(solution, test_inputs, slow_solution)


def test_with_answers(solution, inputs, answers):
    total, wrong = 0, 0
    for args, test_ans in zip(inputs, answers):
        ans = solution(*deepcopy(args))
        if ans != test_ans:
            print('WRONG! ans=%s, test_ans=%s, args=%s' % (ans, test_ans, args))
            wrong += 1
        else:
            print('GOOD')
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_judge(solution, inputs_gen, judge):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        if not judge(deepcopy(ans), *deepcopy(args)):
            print('WRONG! ans=%s, args=%s' % (ans, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_slow_solution(solution, inputs_gen, solution_slow):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        slow = solution_slow(*deepcopy(args))
        if ans != slow:
            print('WRONG! ans=%s, slow=%s, args=%s' % (ans, slow, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))




def mergesort(A, key=lambda x: x, reverse=False):
    C = A
    A = list(range(len(A)))
    B = list(A)

    n = len(A)
    for i in range(0, n - 1, 2):
        if key(C[A[i]]) > key(C[A[i ^ 1]]):
            A[i], A[i ^ 1] = A[i ^ 1], A[i]

    width = 2
    while width < n:
        for i in range(0, n, 2 * width):
            R1, R2 = min(i + width, n), min(i + 2 * width, n)
            j, k = R1, i
            while i < R1 and j < R2:
                if key(C[A[i]]) > key(C[A[j]]):
                    B[k] = A[j]
                    j += 1
                else:
                    B[k] = A[i]
                    i += 1
                k += 1
            while i < R1:
                B[k] = A[i]
                k += 1
                i += 1
            while k < R2:
                B[k] = A[k]
                k += 1
        A, B = B, A
        width *= 2

    if reverse:
        A.reverse()
    return A




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

def read():
    return input()

def read_int():
    return int(input())

def read_array(sep=None, maxsplit=-1):
    return input().split(sep, maxsplit)

def read_int_array():
    return [int(a) for a in read_array()]



if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
ri = lambda: int(input())


rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N,K=rl()

if (N-1)*(N-2)//2 < K:
    print(-1)
else:
    ans = []
    for v in range(2,N+1):
        ans.append((1,v))
    for i in range(2,N):
        if K >= (N-i):
            K -= (N-i)
        elif K == 0:
            for v in range(i+1,N+1):
                ans.append((i,v))
        else:
            for v in range(i+1,N+1-K):
                ans.append((i,v))
            K = 0
    print(len(ans))
    for u,v in ans:
        print(u,v)

Solution (Python):
from itertools import combinations
n,k=map(int,input().split())
m=((n-1)*(n-2))//2
if k>m:
    print(-1)
    exit()
edges=[]
for i in range(2,n+1):
    edges.append((1,i))
add_edges=list(combinations(range(2,n+1),2))
a=m-k
for i in range(m-k):
    edges.append(add_edges[i])
print(len(edges))
for edge in edges:
    print(*edge)

Solution (Python):
N, K = map(int, input().split())

S = (N - 1) * (N - 2) // 2

if K > S:
    print(-1)
else:
    D = S - K
    M = (N - 1) + D
    print(M)
    for i in range(2, N + 1):
        print('{} {}'.format(1, i))
    a, b = 2, 3
    for i in range(D):
        print('{} {}'.format(a, b))
        b += 1
        if b == N + 1:
            a += 1
            b = a + 1

Solution (Python):
N, K = list(map(int ,input().split()))

if K > (N)*(N-1)//2 - (N-1):
  print(-1)

else:  
  M = (N)*(N-1)//2 - K
  print(M)

  for i in range(2,N+1):
    print(*(1,i))

  from itertools import combinations
  L = list(combinations(list(range(2,N+1)),2))

  for l in L[:(N)*(N-1)//2 - K-(N-1)]:
    print(*l)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n, k = na()

if k > (n-1)*(n-2)//2:
    print("-1")
else:
    es = []
    cur = (n-1)*(n-2)//2-k
    for c in range(2, n+1):
        for d in range(2, n+1):
            if c < d and cur > 0:
                es.append((c, d))
                cur -= 1
    for i in range(1, n):
        es.append((1, i+1))
    print(len(es))
    for e in es:
        print(e[0], e[1])

Solution (Python):
N, K = map(int, input().split())


if N == 2:
    if K == 0:
        print(1)
        print(1, 2)
    else:
        print(-1)
    exit()


if (N - 1) * (N - 2) // 2 < K:
    print(-1)
    exit()


M = N * (N - 1) // 2
ans = []
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        ans.append([i, j])

print(M - K)
for i, j in ans[:M - K]:
    print(i, j)

Solution (Python):
N,K = map(int,input().split(' '))

thres = (N-1) * (N-2)//2
if K <= thres:
	M = N-1+thres-K
	print(M)
	for i in range(2,N+1):
		print(1,i)
	need = thres - K
	for i in range(2,N+1):
		for j in range(i+1,N+1):
			if need == 0:
				exit()
			print(i,j)
			need -= 1
else:
	print(-1)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return


def B():
    n,l = LI()
    a = [i+l for i in range(n)]
    ans = sum(a)
    m = n+l-1
    for i in a[::-1]:
        if i < 0:break
        m = min(m,i)
    ans -= m
    print(ans)
    return


def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
def C():
    a,b,c,d = LI()
    g = gcd(c,d)
    l = c*d//g
    sc = b//c-(a-1)//c
    sd = b//d-(a-1)//d
    sl = b//l-(a-1)//l
    print(b-a+1-sc-sd+sl)
    return


def D():
    n = I()
    w = LIR(n)
    w.sort(key = lambda x: x[1])
    t = 0
    for a,b in w:
        if t+a > b:
            print("No")
            quit()
        t += a
    print("Yes")
    return


def E():
    n,k = LI()
    if k == 0:
        m = (n*(n-1))//2
        print(m)
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                print(i,j)
    else:
        if k > ((n-1)*(n-2))//2:
            print(-1)
        else:
            ans = []
            for i in range(2,n+1):
                ans.append((1,i))
            m = ((n-1)*(n-2))//2
            for i in range(2,n+1):
                for j in range(i+1,n+1):
                    if m == k:break
                    ans.append((i,j))
                    m -= 1
                if m == k:break
            print(len(ans))
            for i,j in ans:
                print(i,j)
    return


def F():
    n = I()

    return


if __name__ == "__main__":
    E()

Solution (Python):
n, k = [int(i) for i in input().split()]

if k > (n - 2) * (n - 1) // 2:
    print(-1)
    exit()

E = []

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if j == n:
            E.append((i, j))
            continue
        if k > 0:
            k -= 1
            continue
        E.append((i, j))

print(len(E))
for e in E:
    print(*e)

Solution (Python):
from itertools import combinations

N,K = map(int,input().split())

if (N-2)*(N-1) < 2*K:
    print(-1)
else:
    print(N-1 + (N-2)*(N-1)//2 - K)

    for i in range(2,N+1):
        print(1, i)

    for _,(i,j) in zip(range((N-2)*(N-1)//2 - K), combinations(range(2,N+1), 2)):
        print(i,j)

Solution (Python):



def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    k_max = (n-1)*(n-2)//2
    if k > k_max:
        print(-1)
        return
    edges = []
    edges_dist2 = []
    for i in range(n-1):
        edges.append((i+1, n))
        for j in range(i+1, n-1):
            edges_dist2.append((i+1, j+1))
    print(len(edges) + k_max-k)
    for v1, v2 in edges:
        print(v1, v2)
    for v1, v2 in edges_dist2[:k_max-k]:
        print(v1, v2)


if __name__ == '__main__':
    main()

Solution (Python):
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n,k= map(int, input().split())
    cnt = (n-1) * (n-2) // 2
    if cnt < k:
        print(-1)
        return
    m = (n-1) + cnt-k
    print(m)
    for i in range(n-1):
        print(1, i+2)
    m -= n-1
    for i in range(2, n+1):
        if m == 0:
            return
        for j in range(i+1, n+1):
            if m == 0:
                return
            m -= 1
            print(i, j)


main()

Solution (Python):
n, k = map(int, input().split())

if (n - 1) * (n - 2) // 2 < k:
    print(-1)
    exit()

ans = []
for i in range(n-1):
    ans.append((i, n-1))

cnt = (n - 1) * (n - 2) // 2

for i in range(n-1):
    for j in range(i+1, n-1):
        if cnt > k:
            ans.append((i, j))
            cnt -= 1

print (len(ans))
for a in ans:
    print(a[0]+1, a[1]+1)

Solution (Python):





n,k = [int(i) for i in input().split()]

_max = (n-1)*(n-2)//2




    

if k > _max:
    print(-1)
    exit()

print(n-1 + _max - k)
for i in range(n-1):
    print(1, i+2)

l=2
r=3
for i in range( _max - k):
    print(l,r)
    r += 1
    if r > n:
        l += 1
        r = l+1

Solution (Python):
N, K = map(int, input().split())

ma = (N-1)*(N-2)//2
if K > ma:
    print(-1)
else:
    X = []
    for i in range(1, N):
        X.append((0, i))
    for i in range(1, N):
        for j in range(i+1, N):
            if K == ma:
                break
            X.append((i, j))
            K += 1
        if K == ma:
            break
    print(len(X))
    for a, b in X:
        print(a+1, b+1)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()
MAX = (N-1)*(N-2)//2

def solve(lines):
    print(M)
    for a,b in lines:
        print(a,b)

if MAX < K:
    print(-1)
else:
    M = N-1 + (MAX-K)
    lines = []
    for i in range(N-1):
        lines.append([1,i+2])

    cnt = 0
    if cnt == (MAX-K):
        solve(lines)
        exit()
        
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            lines.append([i,j])
            cnt += 1
            if cnt == (MAX-K):
                solve(lines)
                exit()

Solution (Python):
N,K=map(int,input().split())
MAX=(N-1)*(N-2)//2
if K>MAX:
    print(-1)
else:
    print(N-1+MAX-K)
    for i in range(2,1+N):
        print("1 "+str(i))
    cnt=0
    for i in range(2,N):
        if cnt>=MAX-K:
            break
        for j in range(i+1,1+N):
            print(" ".join(map(str,[i,j])))
            cnt+=1
            if cnt>=MAX-K:
                break

Solution (Python):
import itertools






N,K = map(int,input().split())
x = (N-1)*(N-2)//2
if x < K:
  print(-1)
  exit()


edge = [(1,n) for n in range(2,N+1)]
edge += list(itertools.combinations(range(2,N+1), 2))[:x-K]

print(len(edge))
for x,y in edge:
  print(x,y)