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