#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

#define ll long long

using namespace std;

int up( ll a[], ll n, ll k, ll max )
{
    if( k == n - 1 )
    return 0;
    if( ( a[ k + 1 ] == max ) )
        a[ k + 1 ]--;
    else
        return 0;
    return up( a, n, k + 1, max );
}

int down( ll a[], ll n, ll k, ll max )
{
    if( k == 0 )
    return 0;
    if( ( a[ k - 1 ] == max ) )
        a[ k - 1 ]--;
    else
        return 0;
    return up( a, n, k - 1, max );
}

int main()
{
    ios :: sync_with_stdio( false );
    cin.tie( 0 );
    ll n, max = -1, k = -1, h = 0;
    cin >> n;

    ll a[ n ], x ,y;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> a[ i ];
        if( a[ i ] > max )
        {
            k = i;
            max = a[ i ];
        }
    }
    while( max > 0 )
    {
        a[ k ]--;
        x = up( a, n, k, max );
        y = down( a, n, k, max );
        max = -1;
        k = -1;
        for( ll i = 0 ; i < n ; i++ )
        {
            if( a[ i ] > max )
            {
                k = i;
                max = a[ i ];
            }
        }
        h++;
        /*for( ll i = 0 ; i < n ; i++ )
        {
            cout << a[ i ] << " ";
        }
        cout << endl;*/
    }
    cout << h;
    return 0;
}
