import sys input = sys.stdin.readline int1 = lambda x: int(x) - 1 N = int(input()) K = int(input()) amida = list(range(1, N + 1)) for _ in range(K): x, y = map(int1, input().split()) amida[x], amida[y] = amida[y], amida[x] # print(amida) A = map(int, input().split()) final = [0] * N for i, a in enumerate(A, 1): final[a - 1] = i tmp = [0] * (N + 1) new_amida = [0] * N for i, x in enumerate(amida): tmp[x] = i for i, a in enumerate(final, 1): new_amida[tmp[a]] = i # print(new_amida) # bubblesort ans = [] for i in range(N): for j in reversed(range(i + 1, N)): if new_amida[j - 1] > new_amida[j]: new_amida[j - 1], new_amida[j] = new_amida[j], new_amida[j - 1] ans.append((j, j + 1)) print(len(ans)) for x, y in ans: print(x, y)