program prob6
    implicit none
    integer::n, i, p
    integer, allocatable::c(:)
    read(*,*) n
    allocate(c(0:n))
    c = 0
    do i = 1, n
        read(*,*) p
        if(c(p) == 0 .and. c(p-1) == 0) then
            c(p) = 1
        else if(c(p) == 0) then
            c(p) = c(p-1) + 1
        end if
    end do
    write(*,*) n - maxval(c)
    deallocate(c)
    stop
end program