import java.util.*; class JengaSortFix2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int max = sc.nextInt(); int cnt = max - 1; ArrayList nlist = new ArrayList(); nlist.add(sc.nextInt()); for (int i = 0; i < max - 1; i++) { int next = sc.nextInt(); if (next > JengaSortFix2.maxNum(nlist)) { if (nlist.contains(next - 1)) { cnt--; } else { cnt = max - 1; } nlist.add(next); } } System.out.println(cnt); } private static int maxNum(ArrayList nlist) { int max = 0; for (Integer n : nlist) { int num = n.intValue(); if (num > max) { max = num; } } return max; } }