import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i; } for (int i = 0; i < k; i++) { int idx = sc.nextInt(); sc.nextInt(); int tmp = arr[idx]; arr[idx] = arr[idx - 1]; arr[idx - 1] = tmp; } int[] next = new int[n]; for (int i = 0; i < n; i++) { next[i] = sc.nextInt() - 1; } ArrayList list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = 0; for (int j = i; j < n; j++) { if (arr[j] == next[i]) { idx = j; break; } } for (int j = idx; j > i; j--) { int tmp = arr[j]; arr[j] = arr[j - 1]; arr[j - 1] = tmp; list.add(j); } } StringBuilder sb = new StringBuilder(); sb.append(list.size()).append("\n"); for (int x : list) { sb.append(x).append(" ").append(x + 1).append("\n"); } System.out.print(sb); } }