object Main extends App {
	val N = scala.io.StdIn.readInt
	val a = new Array[Int](N)
	val b = new Array[Int](N)

	for(i<-0 until N){
		val tp = scala.io.StdIn.readInt
		b(tp - 1) = i
	}

	var ans = 1
	var cnt = 1
	for(i<-1 until N){
		if(b(i) > b(i-1)) cnt += 1
		else cnt = 1

		ans = math.max(ans, cnt)
	}

	println(N - ans)
}