#!/usr/bin/env python3
import sys

def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main() import sys sys def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools solve 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 if k < K:
        return None
     k < K k K return None None (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 edges = [(1, i) for i in range(2, N+1)] edges [(1, i) for i in range(2, N+1)] def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
     f for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
     i range(2, N+1) range 2 N+1 N 1 for j in range(i+1, N+1):
                yield i, j
     j range(i+1, N+1) range i+1 i 1 N+1 N 1 yield i, j i j it = f() it f() f while k > K:
        edges.append(next(it))
        k -= 1
     k > K k K edges.append(next(it)) edges.append edges append next(it) next it k -= 1 k 1 return edges edges N: int N K: int K def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens N = int(next(tokens)) N int(next(tokens)) int next(tokens) next tokens K = int(next(tokens)) K int(next(tokens)) int next(tokens) next tokens edges = solve(N, K) edges solve(N, K) solve N K if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1) edges print(len(edges)) print len(edges) len edges for e in edges:
            print(*e)
     e edges print(*e) print *e e print(-1) print -1 def test():
    import doctest
    doctest.testmod() test import doctest doctest doctest.testmod() doctest.testmod doctest testmod if __name__ == '__main__':
    test()
    main() __name__ == '__main__' __name__ '__main__' test() test main() main def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1) main def test():
    import doctest
    doctest.testmod() def test():
    import doctest
    doctest.testmod() test def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools solve
#!/usr/bin/env python3
import sys

def solve(N: int, K: int):
    k = (N - 1) * (N - 2) // 2
    if k < K:
        return None
    edges = [(1, i) for i in range(2, N+1)]
    def f():
        for i in range(2, N+1):
            for j in range(i+1, N+1):
                yield i, j
    it = f()
    while k > K:
        edges.append(next(it))
        k -= 1
    return edges

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    edges = solve(N, K)
    if edges:
        print(len(edges))
        for e in edges:
            print(*e)
    else:
        print(-1)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()
