#include <cstdlib>
#include <iostream>

using namespace std;
int sum(int a[],int h){
    int s = 0;
    for(int x= 0;x<h;x++){
            s+=a[x];
          }
          return s;
    };
    void minus(int b,int a[],int n,int k){
         while((a[b]!=0)&&(b<n)){
                    a[b]--;
                    b++;
                    k++;         
                    };
         };
int main()
{
    int N,K,y,c;
    K = 0;
    y = 0;
    cin >> N;
    int *arr = new int[N];
    for(int i = 0;i < N;i++){
          cin >> arr[i];
          };
          
    while(sum(arr,N)!= 0){
          c = y;
          if(arr[y]!= 0){
                      while((arr[y]!=0)&&(y<N)){
                    arr[y]--;
                    y++;
                           };
                           K++;
                    y = c;
                      }else{
                            y++;
                            }
            };   
            cout<< K;   
          
    
    return 0;
}
