Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

if K > (N - 1)(N - 2) // 2:
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break
    print(M)
    for edge in ans:
        print(*edge)


Fixed submission:
N, K = map(int, input().split())

if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break
    print(M)
    for edge in ans:
        print(*edge)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

if N <= K or N == 2 or (N == 4 and K == 3):
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break
    # print(M)
    # for edge in ans:
    #     print(*edge)


def wf(N):
    INF = 10 ** 6

    dp = [[INF] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    for i, j in ans:
        i -= 1
        j -= 1
        dp[i][j] = 1
        dp[j][i] = 1

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    cnt = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            if dp[i][j] == 2:
                cnt += 1
    return cnt


if wf(N) == K:
    print(M)
    for edge in ans:
        print(*edge)
else:
    print(-1)


Fixed submission:
N, K = map(int, input().split())

if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break
    print(M)
    for edge in ans:
        print(*edge)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

if N <= K:
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break

print(M)
for edge in ans:
    print(*edge)


Fixed submission:
N, K = map(int, input().split())

if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    M = N * (N - 1) // 2 - K
    cnt = 0
    ans = []
    for i in range(N - 1):
        for j in range(i + 1, N):
            ans.append((i + 1, j + 1))
            cnt += 1
            if M == cnt:
                break
        else:
            continue
        break
    print(M)
    for edge in ans:
        print(*edge)