n = gets.to_i k = gets.to_i a = [*0...n] k.times{ x, y = gets.split.map(&:to_i) x -= 1 y -= 1 tmp = a[x] a[x] = a[y] a[y] = tmp } b = gets.split.map(&:to_i) ans = [] n.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}" }