#!/usr/bin/python3

from random import randint

N, K, M = [ int(_) for _ in input().split() ]
G = [ [] for n in range(N) ]
stupen = [ 0 for n in range(N) ]
for m in range(M):
    x, y = [ int(_) for _ in input().split() ]
    G[x].append(y)
    G[y].append(x)
    stupen[x] += 1
    stupen[y] += 1

if K == 0:
    if N == 1:
        print(0)
    else:
        print(-1)
    exit()

if K == 1:
    if N == 1:
        print(0)
    elif N == 2:
        if M == 0:
            print(1)
            print(0, 1)
        else:
            print(0)
    else:
        print(-1)
    exit()

F = 0
farba = [ None for n in range(N) ]
for n in range(N):
    if farba[n] is None:
        farba[n] = F
        todo = [n]
        while len(todo) > 0:
            x = todo.pop()
            for y in G[x]:
                if farba[y] is None:
                    farba[y] = F
                    todo.append(y)
        F += 1

komponenty = [ [] for f in range(F) ]
for n in range(N):
    komponenty[ farba[n] ].append(n)

print(F-1)
for f in range(F-1):
    for x in komponenty[f]:
        if stupen[x] <= 1: break
    for y in komponenty[f+1]:
        if stupen[y] <= 1: break
    print(x, y)
    stupen[y] += 1

