import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] H = new int[N];
        int count = 0;
        int max = 0;
        for (int i = 0 ; i < N ; i++) {
            H[i] = sc.nextInt();
            if (max < H[i]) max = H[i];
        }
        int[][] HN = new int[max][N];
        for (int i = 0; i < max; i++) {
            for (int j = 0; j < N ; j++) {
                if (0 < H[j]) {
                    HN[i][j] = 1;
                    H[j]--;
                } else HN[i][j] = 0;
            }
        }
        for (int[] line : HN) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < line.length; i++) {
                if (i == 0 && line[0] != 0) sb.append(line[i]);
                else if (0 < i && line[i] != line[i-1]) sb.append(line[i]);
                else continue;
            }
            count += sb.toString().split("0").length;
        }
        System.out.println(count);
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz