import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()

def main():
    N,K=mi()

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


    k = (N-1)*(N-2)//2
    v = set([(1,x+1) for x in range(1,N)])


    # print(v)

    for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



    if k != K:
        print(-1)
        exit()

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



if __name__ == "__main__":
  main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 def mi(): return map(int,input().split()) mi def ii(): return int(input()) ii def isp(): return input().split() isp def main():
    N,K=mi()

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


    k = (N-1)*(N-2)//2
    v = set([(1,x+1) for x in range(1,N)])


    # print(v)

    for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



    if k != K:
        print(-1)
        exit()

    print(len(v))
    for x,y in v:
        print(x,y) main N,K=mi() N mi() mi K if not K <= (N-1)*(N-2)//2:
        print(-1)
        exit()


     not K <= (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 print(-1) print -1 exit() exit 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 (1,x+1) for x in range(1,N) for x in range(1,N) x range(1,N) range 1 N for x in range(1,N) (1,x+1) 1 x+1 x 1 v = set([(1,x+1) for x in range(1,N)]) v set([(1,x+1) for x in range(1,N)]) set [(1,x+1) for x in range(1,N)] for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



     i range(2,N+1) range 2 N+1 N 1 for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
         j range(1,N+1) range 1 N+1 N 1 if k <= K: continue

             k <= K k K if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
             i+j <= N and not v in (i,i+j) i+j <= N i+j i j N not v in (i,i+j) v in (i,i+j) v (i,i+j) i i+j i j v.add((i,i+j)) v.add v add (i,i+j) i i+j i j k -= 1 k 1 if k <= K:
                break
         k <= K k K break if k <= K:
            break



     k <= K k K break if k != K:
        print(-1)
        exit()

     k != K k K print(-1) print -1 exit() exit print(len(v)) print len(v) len v for x,y in v:
        print(x,y) x y v print(x,y) print x y if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main def mi(): return map(int,input().split()) def mi(): return map(int,input().split()) mi def isp(): return input().split() def isp(): return input().split() isp def main():
    N,K=mi()

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


    k = (N-1)*(N-2)//2
    v = set([(1,x+1) for x in range(1,N)])


    # print(v)

    for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



    if k != K:
        print(-1)
        exit()

    print(len(v))
    for x,y in v:
        print(x,y) def main():
    N,K=mi()

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


    k = (N-1)*(N-2)//2
    v = set([(1,x+1) for x in range(1,N)])


    # print(v)

    for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



    if k != K:
        print(-1)
        exit()

    print(len(v))
    for x,y in v:
        print(x,y) main def ii(): return int(input()) def ii(): return int(input()) ii
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()

def main():
    N,K=mi()

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


    k = (N-1)*(N-2)//2
    v = set([(1,x+1) for x in range(1,N)])


    # print(v)

    for i in range(2,N+1):
        for j in range(1,N+1):
            if k <= K: continue

            if i+j <= N and not v in (i,i+j):
                v.add((i,i+j))
                # print((i,i+j))
                k -= 1
            if k <= K:
                break
        if k <= K:
            break



    if k != K:
        print(-1)
        exit()

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



if __name__ == "__main__":
  main()