N = int(input())
K = int(input())
amida = list(range(N))
for k in range(K):
    x, y = map(int, input().split())
    amida[x-1], amida[x] = amida[x], amida[x-1]
As = list(map(int, input().split()))
Bs = [0] * N
for i, a in enumerate(As):
    Bs[a - 1] = i

move = []
for i, b in enumerate(Bs):
    pos = amida.index(b)
    while pos > i:
        move.append(pos)
        amida[pos], amida[pos - 1] = amida[pos - 1], amida[pos]
        pos -= 1
print(len(move))
for p in move:
    print(p, p + 1)