#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int(i) = (0); (i) < (n); (i)++) cin >> arr[i];
  int j = 1;
  int ret = 0;
  bool taken[n + 1];
  memset(taken, 0, sizeof taken);
  for (int(i) = (0); (i) < (n); (i)++) {
    if (taken[j])
      j++, i--;
    else if (arr[i] == j)
      j++;
    else
      ret = i + 1, taken[arr[i]] = 1;
  }
  cout << ret << endl;
}
