#!/usr/bin/env python3 import itertools def main(): n = int(input()) k = int(input()) target = list(range(n)) for _ in range(k): x, y = (int(w) - 1 for w in input().split()) target[x], target[y] = target[y], target[x] zs = [int(z) - 1 for z in input().split()] for i in range(n): target[i] = zs[target[i]] ans = [] for _, j in itertools.product(range(n), range(n - 1)): if target[j] > target[j + 1]: target[j], target[j + 1] = target[j + 1], target[j] ans.append((j, j + 1)) print(len(ans)) for x, y in ans: print(x + 1, y + 1) if __name__ == '__main__': main()