#include <bits/stdc++.h>
#define ll long long int
#define N "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//erase not possible when we are using [less equal] instead of [less]
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++){
cin>>a[i];
}
ordered_set s;
vector<ll>vis(n,0);
ll ans=0;
for(ll i=n-1;i>=0;i--){
ll items=(n-i)-s.order_of_key(a[i])-1;
if(items>=a[i]){
ans++;
vis[i]=1;
}
s.insert(a[i]);
}
s.clear();
for(ll i=0;i<n;i++){
if(vis[i]==0){
ll items=s.order_of_key(a[i]+1);
if(items>=a[i]){
ans++;
}
}
s.insert(a[i]);
}
cout<<ans<<N;
return 0;
}