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):
N, K = map(int, input().split())
boundary_value = int((N-1) * (N-2) / 2)

if boundary_value < K:
    print(-1)
else:
    graph = []
    num_side = boundary_value - K

    for i in range(N):
        for j in range(i + 1, N):
            graph.append([i + 1, j + 1])
    
    print(N + num_side - 1)
    for i in range(N + num_side - 1):
        print("%d %d" %(graph[i][0], graph[i][1]))

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

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

cnt = (n-1)*(n-2)//2
m = n-1+(n-1)*(n-2)//2-k

print(m)

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

for i in range(2,n):
    for j in range(i+1,n+1):
        if cnt == k:
            exit()
        print(i,j)
        cnt -= 1

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

if(N == 2 and K != 0):
    print(-1)
    exit()
    
possible = (N-1)*(N-2)//2
if(possible < K):
    print(-1)
    exit()
    
over = possible - K

edge = []
for i in range(2, N+1):
    edge.append((1, i))

additional = []
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if(len(additional) < over):
            additional.append((i, j))
        else:
            break

edge += additional
print(len(edge))
for i in range(len(edge)):
    print(str(edge[i][0]) + ' ' + str(edge[i][1]))

Solution (Python):

n,k=list(map(int,input().split()))
num=int((n-1)*(n-2)/2-k)

if num<0:
    print(-1)
else:
    print(n-1+num)
    for i in range(n-1):
        print(1,i+2)
    total=0
    for i in range(n-1):
        for j in range(i+1,n-1):
            total+=1
            if total>num:
                exit()
            print(i+2,j+2)

Solution (Python):
import sys
n,k=list(map(int,input().split()))
num=int((n-1)*(n-2)/2-k)

if num<0:
    print(-1)
else:
    print(n-1+num)
    for i in range(n-1):
        print(1,i+2)
    total=0
    for i in range(n-1):
        for j in range(i+1,n-1):
            total+=1
            if total<=num:
                print(i+2,j+2)

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

if K > (N-1)*(N-2)/2:
    print(-1)
else:
    edge = []
    for i in range(1, N):
        for j in range(i+1, N+1):
            edge.append([i, j])
    M = int((N-1) + (N-1)*(N-2)/2 - K)
    print(M)
    for ind in range(M):
        print(" ".join(map(str, edge[ind])))

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

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

a = set()
for u in range(1, n):
    a.add((u, n))



rest = lmt - k
if rest > 0:
    for u in range(1, n - 1):
        for v in range(u + 1, n):
            a.add((u, v))
            rest -= 1
            if rest == 0:
                break
        else:
            continue
        break

print(len(a))
for aa in a:
    print(*aa)

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

if (K > (N - 1) * (N - 2) // 2):
  print(-1)
  exit(0)
bstar = (N - 1) * (N - 2) // 2 - K
print(N - 1 + bstar)
for i in range(2, N + 1):
  print(1, i)

for i in range(2, N + 1):
  for j in range(i + 1, N + 1):
    if bstar > 0:
      print(i, j)
      bstar -= 1
    else:
      exit(0)

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

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

cnt_pair = (n - 1) * (n - 2) // 2
to_rm = cnt_pair - k
if to_rm < 0:
    print(-1)
    exit()
elif to_rm == 0:
    print(len(e))
    for ee in e:
        print(*ee)
    exit()

for i in range(1, n - 1):
    for j in range(i + 1, n):
        e.append((i, j))
        to_rm -= 1
        if to_rm == 0:
            break
    else:
        continue
    break

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

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

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

ad = [[0]*N for _ in range(N)]
edges = []

for v in range(1,N):
    ad[0][v] = 1
    ad[v][0] = 1
    edge = (1,v+1)
    edges.append(edge)

pt = (N-1)*(N-2)//2
M = N-1

if pt == K:
    print(M)
    for i,j in edges:
        print(i,j)
    exit()


for v in range(N):
    for nv in range(v+1,N):
        if ad[v][nv] == 0:
            ad[v][nv] = 1
            ad[nv][v] = 1
            edge = (v+1,nv+1)
            edges.append(edge)
            pt -= 1
            M += 1
        if pt == K:
            print(M)
            for i,j in edges:
                print(i,j)
            exit()

Solution (Python):
N,K=map(int,input().split())
a=[[1,i] for i in range(2,N+1)]
M=((N-1)*(N-2))//2
if K>M:
    print(-1)
else:
    b=[[i,j] for i in range(2,N+1) for j in range(i+1,N+1)][K:]
    c=a+b
    print(len(c))
    for i,j in c:
        print(i,j)

Solution (Python):
import itertools as it
def LI(): return list(map(int, input().split()))

def explain(n, k):
    l = (n-1) * (n-2) // 2 - k
    print(n-1 + l) 

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

    
    count = 0
    for i, j in it.combinations(range(2, n+1), 2):
        if count >= l:
            break
        print(i, j)
        count += 1


n, k = LI()

if k > (n-1) * (n-2) // 2:
    print(-1)
else:
    explain(n, k)

Solution (Python):
N, K = map(int, input().split())
max = (N-1)*(N-2)//2
if K > max:
    print(-1)
    exit()

add = max - K
print(N-1 + add)
for i in range(N-1):
    print(1, i+2)
a1, a2 = 2, 2
for i in range(add):
    if a2 == N:
        a1 += 1
        a2 = a1 + 1
    else:
        a2 += 1
    print(a1, a2)

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[n,k]=i2()
 
if k>(n-1)*(n-2)/2:
 print(-1)
else:
 c=(n-1)*(n-2)//2-k
 print(n-1+c)
 for i in range(n-1):
  print(1,i+2)
 
 for i in range(2,n+1):
  if c<=0:
     break
  for j in range(2,n+1):
    if i<j and c>0:
      print(i,j)
      c-=1
    if c<=0:
       break

Solution (Python):

import sys


def solve(N: int, K: int):
    if K > (N * (N-1) / 2) - (N - 1):
        print(-1)
    else:
        elapsed = ((N - 1) * (N - 2) // 2) - K
        print(elapsed + (N - 1))

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

        left_header = 2
        right_header = 3
        for i in range(elapsed):
            print('%d %d' % (left_header, right_header))
            right_header += 1
            if right_header == N+1:
                left_header += 1
                right_header = left_header + 1

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)


if __name__ == '__main__':
    main()

Solution (Python):
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]

if k > (n - 1) * (n - 2) // 2:
    print(-1)
else:
    number = n - 1 + (n - 1) * (n - 2) // 2 - k
    print(number)
    for i in range(n - 1):
        print(1, i + 2)
    u = 2
    v = 2
    for i in range(number - (n - 1)):
        if v == n:
            u = u + 1
            v = u + 1
        else:
            v = v + 1
        print(u, v)

Solution (Python):
n,k=map(int,input().split())
x=(n-1)*(n-2)//2
if x<k:
    print(-1)
else:
    print(-k+x+n-1)
    for i in range(n-1):
        print(1,i+2)
    co=-k+x
    for i in range(3,n+1):
        for j in range(2,i):
            if co==0:
                break
            print(i,j)
            co-=1
        if co==0:
            break

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

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

result = []
for n in range(1, N):
	result += [(1, n + 1)]

l, r = 2, 3
for k in range((((N - 1) * (N - 2)) // 2) - K):
	result += [(l, r)]
	if r == N:
		l += 1
		r = l + 1
	else:
		r += 1

print(len(result))
for v in result:
	print(*v)

Solution (Python):

import sys


def solve(N: int, K: int):
    K_max = (N-1)*(N-2) // 2
    if K > K_max:
        print(-1)
        return

    res = [ (0,i) for i in range(1, N) ]
    e = []
    for i in range(1, N):
        for j in range(i+1, N):
            e.append((i, j))

    add_num = K_max - K
    for i in range(add_num):
        res.append(e[i])

    print(len(res))
    for i, j in res:
        print("{} {}".format(i+1, j+1))



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)

if __name__ == '__main__':
    main()

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

minus = (N - 1) * (N - 2) // 2 - K  

if minus < 0 :
    print('-1')
else :
    print(N - 1 + minus)
    
    for i in range(2,N+1) :
        print('1 {}'.format(i))

    if minus > 0 :
        
        for i in range(2,N+1) :
            for j in range(i+1,N+1) :
                if minus <= 0 :
                    break
                print('{} {}'.format(i,j))
                minus -= 1
            else :
                continue
            break

Solution (Python):
n, k = map(int, input().split())
if k > (n-1)*(n-2)/2:
    print('-1')
else:
    print(int(n*(n-1)/2-k))
    for i in range(n-1):
        print('1', i+2)
    a = (n-2)*(n-1)/2 - k
    if a != 0:
        b = 2
        for j in range(n-1):
            for k in range(n-j-2):
                print(2+j, 3+j+k)
                a = a-1
                if a == 0:
                    break
            if a == 0:
                break

Solution (Python):
N,K=map(int,input().split())
if K>(N-1)*(N-2)/2:
  print("-1")
else:
  print(int(N*(N-1)/2-K))
  for i in range(N-1):
    print("1",i+2)
  a=(N-2)*(N-1)/2-K
  if a!=0:    
    b=2
    for j in range(N-1):
      for k in range(N-j-2):
      	print(2+j,3+j+k)
      	a=a-1
      	if a==0:
      		break
      if a==0:
        break

Solution (Python):
N,K=map(int,input().split())
if K>(N-1)*(N-2)/2:
  print("-1")
else:
  print(int(N*(N-1)/2-K))
  for i in range(N-1):
    print("1",i+2)
  a=(N-2)*(N-1)/2-K
  if a!=0:    
    b=2
    for j in range(N-1):
      for k in range(N-j-2):
        print(2+j,3+j+k)
        a=a-1
        if a==0:
          break
      if a==0:
        break

Solution (Python):

import sys


def solve(N: int, K: int):
    K_max = (N-1)*(N-2) // 2
    if K > K_max:
        print(-1)
        return

    edges = [ [False] * N for _ in range(N) ]

    def star():
        for i in range(1, N):
            edges[0][i] = True
            edges[i][0] = True

    def add_edge():
        for i in range(1, N):
            for j in range(i+1, N):
                if not edges[i][j]:
                    edges[i][j] = True
                    edges[j][i] = True
                    return

    star()
    for i in range(K_max, K, -1):
        add_edge()

    result = []
    for i in range(N):
        for j in range(i+1, N):
            if edges[i][j]:
                result.append((i+1, j+1))

    print(len(result))
    for i, j in result:
        print("{} {}".format(i, j))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    solve(N, K)

if __name__ == '__main__':
    main()

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

def makegraph(num, N): 
  time = 0
  for i in range(N-1):
    for j in range(N-1):
      if time >= num:
        return
      if i<j:
        print(i+2,j+2)
        time+=1

if K > (N-1)*(N-2)/2:
  print('-1')
else:
  num = (N-1)*(N-2)/2 - K
  print(int(N-1+num))
  for i in range(N-1):
    print(i+2, 1)
  time = 0        
  makegraph(num,N)

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

if ((N - 1) * (N - 2)) / 2 < K:
    print(-1)
else:
    point = range(1, N + 1)
    base_line = [[v, point[-1]] for v in point[:-1]]
    add = ((N - 1) * (N - 2)) // 2 - K
    edges = [[i, j] for i in point[:-1] for j in point[i:-1]]

    print(len(base_line) + add)

    for a, b in (base_line + edges[:add]):
        print(a, b)

Solution (Python):
N, K = list(map(int, input().split()))
if K > (((N-1)*(N-2))/2):
    print(-1)
else:
    loop = (((N-1)*(N-2))//2)-K

    print(N-1 + loop)

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

    tree = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]

    for i, j in tree[:loop]:
        print(i, j)

Solution (Python):
n,k = map(int,input().split())
if k > n*(n-1)//2-n+1:
    print(-1)
else:
    ans = []
    for i in range(1,n):
        ans.append((i,n));
    now = 1
    nxt = 2
    cnt = n*(n-1)//2-n+1-k
    for _ in range(cnt):
        ans.append((now,nxt))
        nxt += 1
        if nxt == n:
            now += 1
            nxt = now + 1
    print(len(ans))
    for i,j in ans:
        print(i,j)

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

max_k = (n - 1) * (n - 2) // 2
cut = max_k - k

if cut < 0:
    print(-1)
    exit(0)

print(n - 1 + cut)
for i in range(n - 1):
    print(n, i + 1)

for i in range(n - 1):
    for j in range(i + 1, n - 1):
        if cut > 0:
            print(i + 1, j + 1)
            cut -= 1

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[n,k]=i2()

if k>(n-1)*(n-2)/2:
 print(-1)
else:
 c=(n-1)*(n-2)//2-k
 print(n-1+c)
 for i in range(n-1):
  print(1,i+2)
 
 for i in range(2,n+1):
  if c<=0:
     break
  for j in range(2,n+1):
    if i<j and c>0:
      print(i,j)
      c-=1
    if c<=0:
       break

Solution (Python):
def e_friendships(N, K):
    if K > (N - 1) * (N - 2) // 2:
        return -1

    ans_edge = []
    for i in range(2, N + 1):
        ans_edge.append((1, i))  

    def append_edge(t, lst=[], count=0):  
        for i in range(2, N):
            for j in range(i + 1, N + 1):
                if count == t:
                    return lst
                lst.append((i, j))
                count += 1
        return lst

    ans_edge += append_edge((N - 1) * (N - 2) // 2 - K)
    ans = [(len(ans_edge),)] + ans_edge
    return '\n'.join([' '.join(map(str, row)) for row in ans])

N, K = [int(i) for i in input().split()]
print(e_friendships(N, K))

Solution (Python):
intxt = input().split()
n = int(intxt[0])
k = int(intxt[1])

def graph(n, k):
    edges = [[1, i] for i in range(2, n + 1)]


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

    if k > max_k:
        print(-1)
        return

    diff = max_k - k

    for i in range(2, n + 1):
        if diff == 0:
            break
        for j in range(i + 1, n + 1):
            edges.append([i, j])
            diff -= 1
            if diff == 0:
                break
    
    print(len(edges))
    for i in edges:
        print(str(i[0]) + " " + str(i[1]))

graph(n, k)

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

P = (N - 1) * (N - 2) // 2
if K > P:
    print(-1)
else:
    print(N - 1 + P - K)
    for i in range(2, N + 1):
        print(1, i)
    S, D = 2, 3
    for i in range(P - K):
        print(S, D)
        D += 1
        if D > N:
            S, D = S + 1, S + 2

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

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

if K > max_num:
    print(-1)
else:
    edges = []
    for i in range(2, N + 1):
        edges.append((1, i,))

    add = max_num - K

    candidates = []
    for i in range(2, N):
        for j in range(i + 1, N + 1):
            candidates.append((i, j,))

    for i in range(add):
        edges.append(candidates[i])

    print(len(edges))
    for edge in edges:
        print(' '.join(map(str, edge)))

Solution (Python):



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

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



if e_max < K:
    print(-1)
    exit()


es = []
for j in range(2, N + 1):
    es.append((1, j))



to_join = e_max - K



for i in range(2, N):
    for j in range(i + 1, N + 1):
        if to_join == 0:
            print(len(es))
            for i, j in es:
                print(i, j)
            exit()
        es.append((i, j))
        to_join -= 1

if to_join == 0:
    print(len(es))
    for i, j in es:
        print(i, j)

Solution (Python):
from itertools import combinations
n, k = [int(item) for item in input().split()]
if k > (n - 1) * (n - 2) // 2:
    print(-1)
    exit()

edges = []
for i in range(2, n+1):
    edges.append([1, i])
pairs = (n - 1) * (n - 2) // 2

for i, comb in enumerate(combinations([item for item in range(2, n+1)], 2)):
    if pairs == k:
        break
    else:
        edges.append([comb[0], comb[1]])
        pairs -= 1

print(len(edges))
for first, second in edges:
    print(first, second)

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

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

if m < k:
    print(-1)
    exit()
else:
    print(n-1 + m - k)
    
    for i in range(n-1):
        print(1, i+2)
    
a = m - k
b = 3
for j in range(2, n):
    for l in range(b, n+1):
        if a == 0:
            exit()
        print(j,l)
        a -= 1
    b += 1

Solution (Python):
import heapq

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


n,k = map(int,input().split())


max_vtx = (n-1)*(n-2)*0.5

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


add_line = max_vtx - k


line = int(n-1 + add_line)

print( line )

for i in range(1,n):
    print(1,i+1)

cur = 0

for i in range(2,n+1):
    if cur >= add_line:
            break
    for j in range(3,n+1):
        if i >= j:
            continue
        if cur >= add_line:
            break
        print(i,j)
        cur += 1

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

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

if torisu<K:
	print -1
	quit()

print N-1+(torisu-K)

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

cnt=0
for i in range(2,N+1):
	for j in range(i+1,N+1):
		if cnt==torisu-K:
			quit()
		print i,j
		cnt+=1

Solution (Python):


def main():
    N, K = map( int, input().split())
    t = (N-2)*(N-1)//2
    if K > t:
        print(-1)
        return
    print(N-1+t-K)
    for i in range(1,N):
        print(i, N)
    s = t - K
    cnt = 0
    for i in range(1,N):
        if cnt == s:
            break
        for j in range(i+1, N):
            if cnt == s:
                break
            print(i,j)
            cnt += 1
    return
if __name__ == '__main__':
    main()

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

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

if maxLinks < k:
  print(-1)
else:
  
  links = [(1, x) for x in range(2, n+1)]
  linkNum_to_decrease = maxLinks - k
  num_cost_2 = maxLinks
  for i in range(2, n + 1):
    for j in range(i + 1, n + 1):
      
      if num_cost_2 == k:
   	    break
      else:
        links.append((i,j))
        num_cost_2 -= 1

  print(len(links))
  for link in links:
    print(link[0], link[1])

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

def solve():
  if( (N-1)*(N-2)//2 < K ):
    print('-1')
    return
  print(N-1 + (N-1)*(N-2)//2 - K)
  for i in range(2, N+1):
    print('1', i)
  n = (N-1)*(N-2)//2 - K
  count = 0
  s = 2
  f = 3
  while (count<n):
    print(s, f)
    f+=1
    count+=1
    if(N<f):
      s+=1
      f=s+1

solve()

Solution (Python):
import itertools


num_vertex, target = map(int, input().split(' '))


if num_vertex == 2:
    if target == 0:
        print("1")
        print("1 2")
    else:
        print("-1")

    exit(0)

edges = [(1, i) for i in range(2, num_vertex+1)]
appendable_edges = list(itertools.combinations(range(2, num_vertex+1), 2))

num_removal = len(appendable_edges) - target

if num_removal < 0:
    print("-1")
    exit(0)

edges.extend(appendable_edges[:num_removal])

print(len(edges))
for edge in edges:
    src, dest = edge
    print(src, dest)

exit(0)

Solution (Python):
import itertools


num_vertex, target = map(int, input().split(' '))

target_max = num_vertex - 1


if num_vertex == 2:
    if target == 0:
        print("1")
        print("1 2")
    else:
        print("-1")

    exit(0)

edges = [(1, i) for i in range(2, num_vertex+1)]
appendable_edges = list(itertools.combinations(range(2, num_vertex+1), 2))

num_removal = len(appendable_edges) - target

if num_removal < 0:
    print("-1")
    exit(0)

edges.extend(appendable_edges[:num_removal])

print(len(edges))
for edge in edges:
    src, dest = edge
    print(src, dest)

exit(0)

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






def compgraph(n):
    edges = []
    for i in range(n):
        for j in range(i+1, n):
            edges.append((i+1, j+1))
    return edges

def generategraph(N, pendant, K):
    
    edges = compgraph(N - pendant)
    
    edges.extend([(1, i+1) for i in range(N - pendant, N)])
    
    edges.extend([(i+2, N) for i in range(-K)])
    return edges

for pendant in range(0, N):
    if K <= 0:
        edges = generategraph(N, pendant, K)
        print(len(edges))
        for e in edges:
            print(' '.join(map(str, e)))
        exit()
    K -= N - 2 - pendant

print(-1)

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

Solution (Python):
N,K = map(int,input().split())
 
mx = (N - 1) * (N - 2) // 2
ls = []
if mx < K:
    print(-1)
else:
    M = (N*(N -1) // 2 - K)
    print(M)
    for i in range(1,N+1):
       for j  in range(2,N+1):
           if i < j:
               ls.append([i,j])
               M -= 1
               if M == 0:
                   break
       if M == 0:
           break

if mx >= K:
    for i,j in ls:
        print(i,j)

Solution (Python):
def solve():
 n,k = (int(i) for i in input().split())
 patterns = (n-1)*(n-2)//2
 
 if patterns < k:
    print(-1)
    exit()
 else:
  ans = (n-1)+patterns-k
  print((n-1)+patterns-k)
  for i in range(1,n+1):
    for j in range(i+1,n+1):
     if not i== j:
      if ans == 0:
        exit()
      else:
        ans -= 1
        print(i,j)
     else:
      continue

solve()

Solution (Python):
n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
  print(-1)
else:
  p = (n-1)*(n-2)/2 - k
  print(n-1+int(p))
  for i in range(2,n+1):
    print(1,i)
  x = 2
  y = 3
  for _ in range(int(p)):
    print(x,y)
    y = y + 1
    if y == n + 1:
      x = x + 1
      y = x + 1

Solution (Python):
N, K = [int(x) for x in input().split()]

mx = (N - 1) * (N - 2) // 2
if mx < K:
	print(-1)
else:
	ans = []
	for i in range(N - 1):
		ans.append([i + 1, N])
	add = mx - K
	edge = []
	for i in range(N - 1):
		for j in range(i):
			edge.append([i + 1, j + 1])
	for i in range(add):
		ans.append(edge[i])
	print(len(ans))
	for i in ans:
		print(i[0],end='')
		print(' ',end='')
		print(i[1])

Solution (Python):

'''
完全グラフは距離が全て1のもの
最大の数はスターグラフで一つの頂点を中心に他の組が出ているもの(N-1)(N-2)/2

'''
N, K = map(int,input().split())
mx = (N-1)*(N-2)/2
graph = []
if mx < K:
    print(-1)
else:
    for i in range(N-1):
        star_graph = [i+1 , N]
        graph.append(star_graph)
    band_num = int(mx - K)
    edge = []
    for i in range(N-1):
        for j in range(i):
            edge.append([i+1,j+1])
    for i in range(band_num):
        graph.append(edge[i])
    M = len(graph)
    print(M)
    for i in range(len(graph)):
        print("{0} {1}".format(graph[i][0],graph[i][1]))

Solution (Python):
n, k = map(int, input().split())
_max = (n-1)*(n-2)//2
if k > _max:
    print(-1)
    exit()

ans = []
for i in range(1, n):
    ans.append((1, i+1))
reduce = _max - k
f = 1
t = 2
while reduce:
    ans.append((f+1, t+1))
    reduce -= 1
    if t+1 == n:
        f += 1
        t = f + 1
    else:
        t += 1

print(len(ans))
for a, b in ans:
    print(a, b)

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

if k > (n-1)*(n-2)//2:
  print(-1)
else:
  ans = []
  for i in range(n-1):
    ans.append("{} {}".format(1, i+2))
  u = 2
  v = 3
  for _ in range((n-1)*(n-2)//2 - k):
    ans.append("{} {}".format(u, v))
    v += 1
    if (v > n):
      u += 1
      v = u + 1

  print(len(ans))
  for s in ans:
    print(s)

Solution (Python):
N, K = (int(x) for x in input().split())
if K > (N-1) * (N-2) // 2:
    ans = False
else:
    ans = True
if(not ans):
    print('-1')
else:
    E = (N-1) * (N-2) // 2 - K
    ans1 = E + N - 1
    print('%d' % ans1)
    for i in range(N-1):
        print('1 %d' % (i+2))
    p = 2
    q = 3
    for i in range(E):
        print('%d %d' % (p, q))
        q += 1
        if q > N:
            p += 1
            q = p + 1

Solution (Python):
n,k=map(int,input().split());m=n*(n-1)//2-k;print((-1) if m<(n-1) else ("\n".join([str(m)]+[str(i)+" "+str(j) for i in range(1,n+1) for j in range(i+1,n+1)][:m])))

Solution (Python):
n,k = map(int,input().split())
if k>(n-1)*(n-2)//2:print(-1)
else:print(str(n*(n-1)//2 - k)+"\n"+"\n".join([str(i)+" "+str(j) for i in range(1,n+1) for j in range(i+1,n+1)][:n*(n-1)//2 - k]))

Solution (Python):
n,k = map(int,input().split())
if k>(n-1)*(n-2)//2:print(-1);exit()
m=n*(n-1)//2 - k
print(m)
for i in range(1,n+1):
  for j in range(i+1,n+1):
    if m<=0:break
    m-=1
    print(i,j)

Solution (Python):
n,k = map(int,input().split())
r = (n-1) * (n-2) // 2 - k
if r < 0:
  print(-1)
else:
  print( n - 1 + r )
  for i in range(1,n):
    print(1,i+1)
  for i in range(1,n):
    for j in range(i+1,n):
      if r > 0:
        print(i+1,j+1)
        r -= 1
      else:
        break

Solution (Python):
n,k=map(int,input().split())
k -= (n-1)*(n-2)//2
if k > 0 :
    print(-1)
else:
    print(n-1 - k)
    for i in range(2,n+1):
        print(1,i)
    for i in range(2,n):
        for j in range(i+1,n+1):
            if k < 0:
                print(i,j)
                k += 1

Solution (Python):
from operator import mul
from functools import reduce

def cmb(n,r):
  if n < r:
    return 0
  else:
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

N, K = map(int, input().split())
ma = (N-1)*(N-2)/2

if ma < K:
  print('-1')
else:
  cmb_val = cmb(N-1,2)
  a =[(1, i) for i in range(2, N+1)]
  b = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]
  a.extend(b[:cmb_val-K])
      
  print(len(a))
  for i in range(len(a)):
    print(a[i][0], a[i][1])

Solution (Python):
n,k=map(int,input().split())
extraNode = (n-1)*(n-2)//2 - k

if extraNode < 0:
    print(-1)
    exit()

print(n-1 + extraNode)
for i in range(1,n):
    print(i,n)
l=1
r=1
for  i in range(extraNode):
    r+=1
    if r>=n:
        l+=1
        r=l+1
    print(l,r)

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

all = N*(N-1)//2
one = N-1
two = all - one

if K > two:
    print("-1")
    exit()

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

edge = []
for i in range(1,N):
    for j in range(i+1,N):
        edge.append((i,j))

for i in range(two - K):
    ans.append(edge[i])

print(len(ans))
for i in range(len(ans)):
    print("{0} {1}".format(ans[i][0],ans[i][1]))

Solution (Python):
n, k = list(map(int, input().split()))
m = (n - 1) * (n - 2) / 2
if k > m:
  print(-1)
  exit()
e = []
for i in range(1, n):
  e.append((i, n))
for i in range(1, n):
  for j in range(i + 1, n):
    if m == k:
      break
    e.append((i, j))
    m -= 1
print(len(e))
for u, v in e:
  print("%d %d" % (u, v))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    r = []
    for i in range(2,n+1):
        r.append((1,i))

    t = (n-1) * (n-2) // 2
    if t < k:
        return -1

    for i in range(2,n+1):
        if t == k:
            break
        for j in range(i+1,n+1):
            t -= 1
            r.append((i,j))
            if t == k:
                break

    if t == k:
        return '{}\n{}'.format(len(r), JAA(r,'\n',' '))

    return -1


print(main())

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

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

    extra_edges = MAX - K
    graph = []
    
    for i in range(2,N+1):
        graph.append([1,i])
    
    cnt = 0
    for i in range(2,N):
        for j in range(i+1,N+1):
            if cnt >= extra_edges:
                continue
            graph.append([i,j])
            cnt += 1
    print(len(graph))
    for x,y in graph:
        print(x,y)

if __name__ == "__main__":
    main()

Solution (Python):
n,k = map(int, input().split())
k -= n*(n-1)//2 - (n-1)
if k > 0:
  print(-1)
  exit()
else:
  i = 2
  j = 3
  tl = [(1,f) for f in range(2,n+1)]
  for _ in range(-k):
    tl.append((i,j))
    j += 1
    if j > n:
      i += 1
      j = i+1
print(len(tl))
for x,y in tl:
  print(x,y)

Solution (Python):
import itertools
import math
from collections import defaultdict

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

def solve():
    n, k = input_ints()
    c = (n - 1) * (n - 2) / 2
    if k > c:
        print(-1)
        return
    ans = []
    for i in range(1, n):
        ans.append((i, n))
    for x in range(1, n):
        for y in range(x + 1, n):
            if c > k:
                ans.append((x, y))
                c -= 1
    print(len(ans))
    for p in ans:
        print(p[0], p[1])

if __name__ == '__main__':
    solve()

Solution (Python):
n,k=map(int,input().split())
if k<=(n-1)*(n-2)//2:
    print(n-1+((n-1)*(n-2))//2-k)
    for i in range(2,n+1):
        print(1,i)
    c=0
    for i in range(2,n+1):
        for j in range(i+1,n+1):
            if c==(n-1)*(n-2)//2-k:
                exit()
            print(i,j)
            c+=1
else:
    print(-1)

Solution (Python):
n,k=map(int,input().split())
d=[[i+1,j+1]for i in range(n)for j in range(i+1,n)][::-1][k:]*(k<=(n-2)*~-n//2)
print(len(d)or-1)
for t in d:print(*t)