import java.util.Scanner;

 

public class Main {

 

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int flowerNum = scan.nextInt();                        // 花の総本数
        int[] flowerHeightList = new int[flowerNum];             // 花の高さを入れる配列
        int count = 0;                                             // 水やり回数

 

        /* データ入力 */
        for (int i = 0; i < flowerNum; i++) {
            flowerHeightList[i] = scan.nextInt();
        }

 

        int tmp = 0;
        int head = 0;
        

 

        while(head < flowerNum) {
            // 先頭の高さが0だった場合、次の要素を先頭とする
            if(flowerHeightList[head] == 0) {
                tmp = ++head;
                continue;
            }
            // 水やりの範囲を決定する
            for(int tail = head; tail < flowerNum; tail++) {
                if(flowerHeightList[tail] == 0) {
                    head = tmp;
                    break;
                }
                flowerHeightList[tail]--;
            }
            count++;
        }

 

        System.out.println(count);
        scan.close();
    }

 

}
/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