#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU ############################################################ def gs() gets.chomp end def gi() gets.to_i end def gss() gets.chomp.split end def gis() gss.map(&:to_i) end def nmapf(n,f) n.times.map{ __send__ f } end def arr2d(h,w,v=0) h.times.map{[v] * w} end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end def nsum(n) n * (n + 1) / 2 end ############################################################ N = gi f = (0..N).to_a K = gi K.times do x, y = gis f[x], f[y] = f[y], f[x] end A = gis (1..N).each do |i| f[i] = A[f[i] - 1] end ans = [] (1..N).each do |i| next if f[i] == i j = f.index(i) while j > i ans << "%d %d" % [j - 1, j] f[j - 1], f[j] = f[j], f[j - 1] j -= 1 end end puts ans.size puts ans * "\n"