import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] nums = new int[n]; int[] pos = new int[n + 1]; for (int i = 0; i < n; i++) { nums[i] = sc.nextInt(); pos[nums[i]] = i; } System.out.println(solve(nums, pos)); sc.close(); } public static int solve (int[] nums, int[] pos) { for (int i = nums.length; i > 1; i--) if (pos[i] < pos[i - 1]) return i - 1; return 0; } }