n,k,*d=`dd`.split.map &:to_i x=[] c=0 n.times{|i|x[d[i]]=i} 1.upto(n){|i|(a=d[m=i-1])==i||(c+=1;d[x[i]],d[m],x[a],x[i]=a,i,x[i],m)}