n = gets.to_i a = Array.new(n+1){|i| i} gets.to_i.times do x, y = gets.split.map(&:to_i) a[x], a[y] = a[y], a[x] end w = gets.split.map(&:to_i).unshift(0) ans = [] (n-1).downto(1) do |to| for i in 1..to do if w[a[i]] > w[a[i+1]] then ans << [i, i+1] a[i], a[i+1] = a[i+1], a[i] end end end puts ans.size puts ans.map{|a| a.join(" ")}