import java.util.*; import java.math.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { int n = sc.nextInt(); int[] ary = new int[n+1]; for (int i = 1;i <= n;i++) { ary[i] = sc.nextInt(); } int ret = 0; int max = n; for (int i = n;i > 0;i--) { if (ary[i]==max) { ret++; max--; } } System.out.println(n-ret); } }