#include <bits/stdc++.h>
int n[100005];
bool vis[100005];
int cur;
void next() {
  cur++;
  while (vis[cur]) cur++;
}
int main() {
  int i, t, res;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d", &n[i]);
  }
  next();
  res = 0;
  for (i = 0; i < t; i++) {
    if (n[i] != cur) {
      res = i + 1;
      vis[n[i]] = true;
    } else
      next();
  }
  printf("%d", res);
  return 0;
}
