

def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)    



if __name__ == "__main__":
    resolve() def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)     resolve N,K =map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K if K > ((N-1)*(N-2))//2:
        print(-1)
        return
     K > ((N-1)*(N-2))//2 K ((N-1)*(N-2))//2 (N-1)*(N-2) N-1 N 1 N-2 N 2 2 print(-1) print -1 return (1,i) for i in range(2,N+1) for i in range(2,N+1) i range(2,N+1) range 2 N+1 N 1 for i in range(2,N+1) (1,i) 1 i XX = [(1,i) for i in range(2,N+1)] XX [(1,i) for i in range(2,N+1)] xx2=[] xx2 [] for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

     i range(2,N+1) range 2 N+1 N 1 for j in range(i+1,N+1):
            xx2.append((i,j))

     j range(i+1,N+1) range i+1 i 1 N+1 N 1 xx2.append((i,j)) xx2.append xx2 append (i,j) i j xx2 = xx2[:((N-1)*(N-2))//2-K] xx2 xx2[:((N-1)*(N-2))//2-K] xx2 :((N-1)*(N-2))//2-K ((N-1)*(N-2))//2-K ((N-1)*(N-2))//2 (N-1)*(N-2) N-1 N 1 N-2 N 2 2 K ans = XX+xx2 ans XX+xx2 XX xx2 print(len(ans)) print len(ans) len ans for i,j in ans:
        print(i,j)     i j ans print(i,j) print i j if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)     def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)     resolve


def resolve():
    N,K =map(int,input().split())

    if K > ((N-1)*(N-2))//2:
        print(-1)
        return
    XX = [(1,i) for i in range(2,N+1)]
    xx2=[]
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            xx2.append((i,j))

    xx2 = xx2[:((N-1)*(N-2))//2-K]

    ans = XX+xx2
    print(len(ans))

    for i,j in ans:
        print(i,j)    



if __name__ == "__main__":
    resolve()