import java.util.Scanner; public class Test { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(), k = sc.nextInt(), a, b, tmp, cnt = 0; String[] s = new String[n * (n - 1) / 2]; int[] t = new int[n + 1], m = new int[n + 1]; for (int i = 1; i <= n; i++) { t[i] = i; } for (int i = 0; i < k; i++) { a = sc.nextInt(); b = sc.nextInt(); tmp = t[a]; t[a] = t[b]; t[b] = tmp; } for (int i = 1; i <= n; i++) { tmp = sc.nextInt(); m[tmp] = i; } for (int i = 1; i < n; i++) { if (t[i] == m[i]) { continue; } for (int j = i + 1; j <= n; j++) { if (t[j] == m[i]) { for (int l = j; l > i; l--) { tmp = t[l - 1]; t[l - 1] = t[l]; t[l] = tmp; s[cnt] = (l - 1) + " " + l; cnt++; } break; } } } System.out.println(cnt); for (int i = 0; i < cnt; i++) { System.out.println(s[i]); } } }