import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main
if __name__ == '__main__':
    AtCoder().main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main AtCoder def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main main N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K max_pair = (N - 1) * (N - 2) // 2 max_pair (N - 1) * (N - 2) // 2 (N - 1) * (N - 2) N - 1 N 1 N - 2 N 2 2 if K > max_pair:
            print(-1)
            exit()

         K > max_pair K max_pair print(-1) print -1 exit() exit star = [] star [] for i in range(1, N):
            star.append((i, N))

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

         i range(1, N) range 1 N for j in range(1, i):
                leaves.append((i, j))

         j range(1, i) range 1 i leaves.append((i, j)) leaves.append leaves append (i, j) i j star += leaves[:max_pair - K] star leaves[:max_pair - K] leaves :max_pair - K max_pair - K max_pair K print(len(star)) print len(star) len star for pair in star:
            print(" ".join(map(str, pair)))


# Run main pair star print(" ".join(map(str, pair))) print " ".join(map(str, pair)) " ".join " " join map(str, pair) map str pair self self if __name__ == '__main__':
    AtCoder().main() __name__ == '__main__' __name__ '__main__' AtCoder().main() ().main () AtCoder main input = sys.stdin.readline sys.stdin.readline input class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main AtCoder
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

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

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

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main
if __name__ == '__main__':
    AtCoder().main()
