#include <bits/stdc++.h>
using namespace std;

typedef int ll;
const int INF = 100005;

ll n, dist;
ll dis[INF], box[100000005], a[INF], boxcount, counter, ans;

int main()
{
    counter = 0;
    boxcount = 0; ans = 0;
    cin >> n;
    for(int i=1; i <= n; i++){
        cin >> dis[i]; box[dis[i]]++; a[i] = dis[i];
        dist = dis[i] - boxcount;
        if(dist >= n-i) {
            //cout << "first" << endl;
            ans += dis[i] - n + i + box[dis[i]] - 1;
        }
        else{
            //cout << "second" << endl;
            ans += dis[i] - dist + box[dis[i]] - 1;
        }
        counter++;
        //cout << " " << ans << endl;
        if(box[dis[i]] == 1) boxcount++;
    }
    cout << ans << endl;

    return 0;
}
