import java.util.*; public class Exercise53{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int vert = sc.nextInt(); int hori = sc.nextInt(); int[][] lines = new int[hori][2]; for (int a = 0; a < hori; a++){ lines[a][0] = sc.nextInt(); lines[a][1] = sc.nextInt(); } int[] answer = new int[vert]; for (int b = 0; b < vert; b++){ answer[b] = sc.nextInt(); } LinkedList newLines1 = new LinkedList(); LinkedList newLines2 = new LinkedList(); int[] process = new int[vert]; for (int i = 0; i < vert; i++){ int currentNum = i + 1; for (int j = 0; j < hori; j++){ if (currentNum == lines[j][0]){ currentNum++; }else if(currentNum == lines[j][1]){ currentNum--; } } process[i] = currentNum; } getNewHori(vert, process, newLines1, true); getNewHori(vert, answer, newLines2, false); System.out.println(newLines1.size() + newLines2.size()); showLines(newLines1); showLines(newLines2); } private static void getNewHori(int vert, int[] array, LinkedList arrayList, boolean flag){ for (int k = 0; k < vert - 1; k++){ for (int i = vert - 1; i > k; i--){ if (array[i] < array[i - 1]){ int w = array[i]; array[i] = array[i - 1]; array[i - 1] = w; int[] newLine = new int[2]; newLine[0] = i; newLine[1] = i + 1; if (flag){ arrayList.push(newLine); }else{ arrayList.add(newLine); } } } } } private static void showLines(LinkedList arrayList){ for (int i = 0; i < arrayList.size(); i++){ int[] line = arrayList.get(i); System.out.println(line[0] + " " + line[1]); } } }