n=input() R=range K=R(input()) r=lambda:map(int, raw_input().split()) m=R(n) for i in K:x,y=r();m[x],m[y-2]=m[y-2],m[x] a=r() m=[m.index(a.index(i+1))for i in R(n)] A=[] for i in R(n): for j in R(1,n): if m[j-1]>m[j]:m[j],m[j-1]=m[j-1],m[j];A+=[j] print len(A) for x in A[::-1]:print x,x+1