n = int(input()) k = int(input()) P = [i for i in range(n)] for _ in range(k): x, y = map(int, input().split()) x -= 1 y -= 1 P[x], P[y] = P[y], P[x] A = list(map(int, input().split())) A = [a - 1 for a in A] invA = [-1] * n for i, a in enumerate(A): invA[a] = i ans = [] for i, a in enumerate(A): while P[i] != a: p = invA[P[i]] ans.append((i + 1, p + 1)) P[i], P[p] = P[p], P[i] print(len(ans)) for row in ans: print(*row)