import java.util.*; public class No326{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); int[][] xy = new int[K][2]; for(int i = 0; i < K; i++){ xy[i][0] = sc.nextInt()-1; xy[i][1] = sc.nextInt()-1; } // int[] A = new int[N]; // int[] A_tmp = new int[N]; ArrayList A = new ArrayList(); ArrayList A_tmp = new ArrayList(); for(int i = 0; i < N; i++){ A.add(sc.nextInt()); A_tmp.add(i+1); } for(int i = 0; i < K; i++){ int a_left = A_tmp.get(xy[i][0]); int a_right = A_tmp.get(xy[i][1]); A_tmp.set(xy[i][0], a_right); A_tmp.set(xy[i][1], a_left); } // System.out.println(A_tmp.toString()); ArrayList> ans = new ArrayList>(); for(int i = 0; i < N; i++){ if(A_tmp.get(i) != A.get(i)){ int idx_left = i; int a_left = A_tmp.get(i); int idx_right = A.indexOf(A_tmp.get(i)); int a_right = A_tmp.get(idx_right); A_tmp.set(idx_left, a_right); A_tmp.set(idx_right, a_left); ArrayList xy_new = new ArrayList(); xy_new.add(idx_left+1); xy_new.add(idx_right+1); ans.add(xy_new); } } System.out.println(ans.size()); for(int i = 0; i < ans.size(); i++){ System.out.println(ans.get(i).get(0)+" "+ans.get(i).get(1)); } } }