import java.util.*; class JengaSortFix3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int length = sc.nextInt(); int cnt = length - 1; HashSet nset = new HashSet(); int maxInSet = sc.nextInt(); nset.add(maxInSet); for (int i = 0; i < length - 1; i++) { int next = sc.nextInt(); if (next > maxInSet) { maxInSet = next; if (nset.contains(next - 1)) { cnt--; } else { cnt = length - 1; } nset.add(next); } } System.out.println(cnt); } }