import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] current = new int[N]; for(int i = 0; i < N; i++){ current[i] = i; } final int K = sc.nextInt(); for(int i = 0; i < K; i++){ final int X = sc.nextInt() - 1; final int Y = sc.nextInt() - 1; { final int tmp = current[X]; current[X] = current[Y]; current[Y] = tmp; } } //System.out.println(Arrays.toString(current)); int[] purpose = new int[N]; for(int i = 0; i < N; i++){ purpose[i] = sc.nextInt(); } LinkedList answers = new LinkedList(); for(int i = 0; i < N; i++){ if(current[i] != purpose[i]){ for(int index = 0; index < N; index++){ if(current[index] != purpose[i]){ continue; } { answers.add((i + 1) + " " + (index + 1)); int tmp = current[index]; current[index] = current[i]; current[i] = tmp; break; } } } } System.out.println(answers.size()); for(String str : answers){ System.out.println(str); } //System.out.println(Arrays.toString(purpose)); } }