#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    t=t-1;
    int a[t];
    int c=0;
    int x=0;
      while (c<=t)
       {
          cin >> a[c];
          c++;
       }
    int i=0;
    int C = 1;

    int p = 0;


    while (C>0)
  {

    while(i<=t)
    {

        if(a[i]>p)
        {
         a[i]=a[i]-1;
         i++;
         while((a[i]>p)&&(i<=t))
         {
             a[i]=a[i]-1;
             i++;
         }
         x++;
        }
        else
        i++;
    }

    i=0;

    C = 0;
    while (i<=t)
    {
        if (a[i]>0)
        {
            C++;
            i++;
        }
        else
            i++;
    }
    i=0;
    }




    cout << x;

}
