#include <bits/stdc++.h>
//#define endl'\n'
using namespace std;
long long n,res,s,sh,l,nb,v;
deque<int>q;
int main(){ //   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>v;
        q.push_front(v);
    }
    sort(q.begin(),q.end());
    while(n>0){
        res=res+(q.back()-sh);
        nb=q.back();
        q.pop_back();
        n--;
        s++;
        if(q.front()==s){q.pop_front();n--;}
        if(q.back()!=nb)sh=s;
    }

    cout<<res;

return 0;}
