i = input n = int(i()) now = list(range(1, n+1)) k = int(i()) for _ in range(k): x, y = map(int, i().split()) now[x-1], now[y-1] = now[y-1], now[x-1] A = list(map(int, i().split())) ans = list() for i, elm in enumerate(A): if now[i] == elm: continue j = now.index(elm) while j != i: ans.append( (j, j+1) ) now[j-1], now[j] = now[j], now[j-1] j -= 1 print(len(ans)) for x, y in ans: print(x, y)