from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc131/tasks/abc131_e
# E - Friendships
"""

"""

N = gi()
K = gi()


def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

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

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u)


run() from _collections import deque from _ast import Num def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) 1 data = list(input().split(' ')) data list(input().split(' ')) list input().split(' ') ().split () input split ' ' for number in data:
            if len(number) > 0:
                yield (number) number data if len(number) > 0:
                yield (number) len(number) > 0 len(number) len number 0 yield (number) number input_parser = parser() input_parser parser() parser def gw():
    global input_parser
    return next(input_parser) gw global input_parser return next(input_parser) next(input_parser) next input_parser def gi():
    data = gw()
    return int(data) gi data = gw() data gw() gw return int(data) int(data) int data MOD = int(1e9 + 7) MOD int(1e9 + 7) int 1e9 + 7 1e9 7 import numpy numpy from collections import deque from math import sqrt from math import floor """

""" N = gi() N gi() gi K = gi() K gi() gi def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

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

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u) run M = N - 1 M N - 1 N 1 d = ((N - 1) * (N - 2)) // 2 - K d ((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 M += d M d if M < (N - 1):
        print(-1)
        return

     M < (N - 1) M N - 1 N 1 print(-1) print -1 return print(M) print M for v in range(2, N + 1):
        print(1, v)

     v range(2, N + 1) range 2 N + 1 N 1 print(1, v) print 1 v for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u) v range(2, N + 1) range 2 N + 1 N 1 for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u) u range(v + 1, N + 1) range v + 1 v 1 N + 1 N 1 if not d:
                return
             not d d return d -= 1 d 1 print(v, u) print v u run() run K = gi() gi() K input_parser = parser() parser() input_parser def gi():
    data = gw()
    return int(data) def gi():
    data = gw()
    return int(data) gi def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number) parser def gw():
    global input_parser
    return next(input_parser) def gw():
    global input_parser
    return next(input_parser) gw MOD = int(1e9 + 7) int(1e9 + 7) MOD def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

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

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u) def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

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

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u) run N = gi() gi() N
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc131/tasks/abc131_e
# E - Friendships
"""

"""

N = gi()
K = gi()


def run():
    M = N - 1
    d = ((N - 1) * (N - 2)) // 2 - K
    M += d

    if M < (N - 1):
        print(-1)
        return

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

    for v in range(2, N + 1):
        for u in range(v + 1, N + 1):
            if not d:
                return
            d -= 1
            print(v, u)


run()
