#include <iostream>
#include <math.h>
#include <string>
//xy5519
using namespace std;

int main()
{
    int amout;
    int big=2;
    int bigNum;
    int nowNum;
    int Answer;


    cin>>amout;
    int *row = new int[amout];
    for(int i=0;i<amout;i++)
    {
        cin>>row[i];
    }
    for(int turns=1;big!=1;turns++)
    {
        big=0;

    for(int i=0;i<amout;i++)
    {
        if(big<row[i])
        {
            big=row[i];
            bigNum=i;
        }
    }
    for(int i = bigNum;i<amout;i++)
    {
        nowNum=row[i];
        if(nowNum>=big)
        {
            row[i]-=1;
        }
        else
        {
            break;
        }
    }
    Answer=turns;
    }
    cout<<Answer;


    return 0;
}
