n = gets.to_i k = gets.to_i a = [*1..n] k.times{ x, y = gets.split.map(&:to_i) x -= 1 y -= 1 tmp = a[x] a[x] = a[y] a[y] = tmp } c = gets.split.map(&:to_i) b = Array.new(n + 1) n.times{|i| b[c[i]] = i } ans = [] (n - 1).times{|i| 1.upto(n - i - 1){|j| if b[a[j]] < b[a[j - 1]] tmp = a[j] a[j] = a[j - 1] a[j - 1] = tmp ans.push(j) end } } s = ans.size p s s.times{|i| puts "#{ans[i]} #{ans[i] + 1}" }