n = gets.to_i
k = gets.to_i
a = Array.new(n)
b = Array.new(n)
x = Array.new(n)
y = Array.new(n)
n.times do |i|
    a[i] = i + 1
end
k.times do
    s1, s2 = gets.split.map(&:to_i)
    a[s1 - 1], a[s1] = a[s1], a[s1 - 1]
end
b = gets.split.map(&:to_i)
n.times do |i|
    x[a[i] - 1] = i + 1
    y[b[i] - 1] = i + 1
end
res = Array.new(2).map{Array.new}
n.times do |i|
    next if a[i] == y[i]
    j = 0
    while y[i] != a[j]
        j += 1
    end
    while i != j
        a[j], a[j - 1] = a[j - 1], a[j]
        res[0].push(j)
        res[1].push(j + 1)
        j -= 1
    end
end
puts res[0].length
res[0].length.times do |i|
    print res[0][i], " ", res[1][i], "\n"
end