#include <iostream>
using namespace std;
int main()
{
    long long n,a[10000],i,s,f,k;
    cin>>n;
    s=0;
    for(i=0;i<n;i++)
        cin>>a[i];
    f=n-1;
    for(i=n-1;i>=0;i--)
    {

        k=a[i]+i+1-n;

        if(k<0) k=0;
        
        if(a[i]==a[f]) 
            k=a[f]+f+1-n;
        else
            f=i;
        s+=k;
    }
    cout << s;
} 