#include <cstdlib>
#include <iostream>

using namespace std;

void FindLargest();
void StartTheParty();

int arr[256000];
int N, biggest, index, party = 0;

int main(int argc, char *argv[])
{
    cin >> N;
    for (int i = 0; i < N; i++) cin >> arr[i]; 
    FindLargest();
    cout << party;
    return EXIT_SUCCESS;
}


void FindLargest(){
     biggest = 0;
     index = 0;
     for (int i = 0; i < N; i++){
         if(arr[i] > biggest){
                   biggest = arr[i];
                   index = i;
                   }
         }
     if (biggest != 0) StartTheParty();
     }
     
void StartTheParty(){
     party++;
     int iteration = index;
     while(arr[iteration] == biggest){
                     arr[iteration]--;
                     iteration++;
                     }
     FindLargest();
     }
