N,K=(int(x) for x in input().split(" "))
def comb(n):
    return int(n*(n-1)/2)
limit=comb(N-1)
max=comb(N)

if K>limit:
    print (-1)
else:
    print (max-K)
    a=0
    for i in range (1,N+1):
        for j in range (i+1,N+1):
            if a<max-K:
                a+=1
            else:
                break
            c=str(i)
            d=str(j)
            print (c+" "+d)
        if a>=max-K:
            break int(x) for x in input().split(" ") for x in input().split(" ") x input().split(" ") ().split () input split " " for x in input().split(" ") int(x) int x N,K=(int(x) for x in input().split(" ")) N (int(x) for x in input().split(" ")) K def comb(n):
    return int(n*(n-1)/2) comb return int(n*(n-1)/2) int(n*(n-1)/2) int n*(n-1)/2 n*(n-1) n n-1 n 1 2 n n limit=comb(N-1) limit comb(N-1) comb N-1 N 1 max=comb(N) max comb(N) comb N if K>limit:
    print (-1)
else:
    print (max-K)
    a=0
    for i in range (1,N+1):
        for j in range (i+1,N+1):
            if a<max-K:
                a+=1
            else:
                break
            c=str(i)
            d=str(j)
            print (c+" "+d)
        if a>=max-K:
            break K>limit K limit print (-1) print -1 print (max-K) print max-K max K a=0 a 0 for i in range (1,N+1):
        for j in range (i+1,N+1):
            if a<max-K:
                a+=1
            else:
                break
            c=str(i)
            d=str(j)
            print (c+" "+d)
        if a>=max-K:
            break i range (1,N+1) range 1 N+1 N 1 for j in range (i+1,N+1):
            if a<max-K:
                a+=1
            else:
                break
            c=str(i)
            d=str(j)
            print (c+" "+d)
         j range (i+1,N+1) range i+1 i 1 N+1 N 1 if a<max-K:
                a+=1
            else:
                break
             a<max-K a max-K max K a+=1 a 1 break c=str(i) c str(i) str i d=str(j) d str(j) str j print (c+" "+d) print c+" "+d c+" " c " " d if a>=max-K:
            break a>=max-K a max-K max K break c=str(i) str(i) c K=(int(x) for x in input().split(" ")) (int(x) for x in input().split(" ")) K def comb(n):
    return int(n*(n-1)/2) def comb(n):
    return int(n*(n-1)/2) comb N,K=(int(x) for x in input().split(" ")) (int(x) for x in input().split(" ")) N limit=comb(N-1) comb(N-1) limit a=0 0 a max=comb(N) comb(N) max d=str(j) str(j) d a+=1 1 a
N,K=(int(x) for x in input().split(" "))
def comb(n):
    return int(n*(n-1)/2)
limit=comb(N-1)
max=comb(N)

if K>limit:
    print (-1)
else:
    print (max-K)
    a=0
    for i in range (1,N+1):
        for j in range (i+1,N+1):
            if a<max-K:
                a+=1
            else:
                break
            c=str(i)
            d=str(j)
            print (c+" "+d)
        if a>=max-K:
            break