program test
implicit none
integer :: n,i,j,k,l,t,combo,max_combo
integer :: retsu(2*10**5) = 0, jyunjyo(2*10**5) = 0

read(*,*) n

do i=1,n
	read(*,*) retsu(i)
enddo

do i=1,n
	jyunjyo(retsu(i)) = i
enddo

max_combo = 1
combo = 1

do i = 1,n-1
	if(jyunjyo(i+1) > jyunjyo(i)) then
		combo = combo + 1
		max_combo = max(combo,max_combo)
	else
		combo = 1
	endif
enddo

write(*,*) n-max_combo

end program