#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
o_set<int> l, r;
for (auto &x : v)
{
cin >> x;
r.insert(x);
}
int ans = 0;
for (int i = 0; i < n; i++)
{
int x = v[i];
r.erase(x);
int chuto = l.order_of_key(x + 1);
if (chuto >= x)
{
ans++;
l.insert(x);
continue;
}
int boro = r.size() - r.order_of_key(x);
if (boro >= x)
{
ans++;
}
l.insert(x);
}
cout << ans << '\n';
return 0;
}