import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class JengaSort { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); List list = new ArrayList(); for (int i = 0; i < N; i++) { list.add(sc.nextInt()); } int base = list.get(N - 1); int count = 0; for (int i = N-1; i > 0; i--) { int next = list.get(i - 1); if (next == base - 1) { base = next; } else { count++; } } System.out.println(count); } }