//https://atcoder.jp/contests/abc116/tasks/abc116_c

import java.util.Scanner;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] h = new int[N]; h new int[N] N for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            h[i] = sc.nextInt();
        } {
            h[i] = sc.nextInt();
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int area = 0; area 0 int ans = 0; ans 0 for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        } {
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        } if (h[i]==0){
                ans += area;
                area = 0;
            } h[i]==0 h[i] h i 0 {
                ans += area;
                area = 0;
            } ans += area ans area area = 0 area 0 if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            } h[i]>= area h[i] h i area {
                area = h[i];
            } area = h[i] area h[i] h i {
                ans += area - h[i];
                area = h[i];
            } ans += area - h[i] ans area - h[i] area h[i] h i area = h[i] area h[i] h i ans += area ans area System.out.println(ans) System.out.println System.out System System.out ans String[] args args
//https://atcoder.jp/contests/abc116/tasks/abc116_c

import java.util.Scanner;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        int area = 0;
        int ans = 0;
        for (int i=0;i<N;i++){
            if (h[i]==0){
                ans += area;
                area = 0;
            }
            if (h[i]>= area){
                area = h[i];
            } else {
                ans += area - h[i];
                area = h[i];
            }
        }
        ans += area;
        System.out.println(ans);
    }
}