#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n;
  set<int> st;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int cur = n, ans = 0;
  for (int i = n; i > 0; i--) {
    if (st.find(a[i]) != st.end()) {
      ans = i;
      break;
    }
    while (a[i] != cur) st.insert(cur), cur--;
    cur--;
  }
  cout << ans << endl;
  return 0;
}
