#include <iostream>
#include <bits/stdc++.h>

using namespace std;

unsigned int  max_ind (long long M[200000],  unsigned int n )
{
    unsigned int dop=0;
    for (unsigned int i=1; i<n; i++)
        if (M[dop]<M[i])
        dop=i;
    return dop;
}

unsigned long long sum(long long M[200000],  unsigned int n )
{
   unsigned long long s=0;
   for (unsigned int i=0; i<n; i++)
    s+=M[i];
   return s;
}


int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    unsigned int n,index,counter;
    long long arr[200000];
    cin >> n;
    for (unsigned int i=0; i<n; i++)
        cin >> arr[i];
    arr[n]=0;
    //cout << sum(arr,n);
    for (counter=0; sum(arr,n)>0; counter++)
    {
        index=max_ind(arr,n);
        for (unsigned int j=index+1; (arr[j]==arr[index]) && (j<n) ; j++)
            arr[j]--;
        arr[index]--;
    }
    cout << counter;
    return 0;
}
