n = gets.to_i
k = gets.to_i
amida = n.times.map {|i| i}
k.times do
  x, y = gets.chomp.split.map {|i| i.to_i - 1}
  amida[x], amida[y] = amida[y], amida[x]
end

a_list = Array.new(n)
gets.chomp.split.each_with_index {|a, i| a_list[a.to_i - 1] = i}
b_list = []

a_list.each_with_index do |a, i|
  dest_index = amida.find_index(a)
  next if dest_index == i
  amida.delete_at(dest_index)
  amida.insert(i, a)
  dest_index.downto(i+1) {|k| b_list.push "#{k} #{k+1}"}
end

puts b_list.length
b_list.each {|b| puts b}