#!/usr/bin/env python3 n = int(input()) f = list(range(1,n+1)) for _ in range(int(input())): x, y = map(int,input().split()) x -= 1 y -= 1 f[x], f[y] = f[y], f[x] sigma = list(map(int,input().split())) for i in range(n): f[i] = sigma[f[i] - 1] - 1 ans = [] for i in range(n): for j in range(n-1): if f[j] > f[j+1]: f[j], f[j+1] = f[j+1], f[j] ans += [(j, j+1)] print(len(ans)) for x, y in ans: print(x+1, y+1)