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();
    }

 

} import java.util.Scanner; Scanner java.util 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();
    }

 

} 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();
    } main {
        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();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int flowerNum = scan.nextInt(); flowerNum scan.nextInt() scan.nextInt scan int[] flowerHeightList = new int[flowerNum]; flowerHeightList new int[flowerNum] flowerNum int count = 0; count 0 for (int i = 0; i < flowerNum; i++) {
            flowerHeightList[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < flowerNum i flowerNum i++ i++ i {
            flowerHeightList[i] = scan.nextInt();
        } {
            flowerHeightList[i] = scan.nextInt();
        } flowerHeightList[i] = scan.nextInt() flowerHeightList[i] flowerHeightList i scan.nextInt() scan.nextInt scan int tmp = 0; tmp 0 int head = 0; 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++;
        } head < flowerNum 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++;
        } if(flowerHeightList[head] == 0) {
                tmp = ++head;
                continue;
            } flowerHeightList[head] == 0 flowerHeightList[head] flowerHeightList head 0 {
                tmp = ++head;
                continue;
            } tmp = ++head tmp ++head head continue; for(int tail = head; tail < flowerNum; tail++) {
                if(flowerHeightList[tail] == 0) {
                    head = tmp;
                    break;
                }
                flowerHeightList[tail]--;
            } int tail = head; int tail = head; tail head tail < flowerNum tail flowerNum tail++ tail++ tail {
                if(flowerHeightList[tail] == 0) {
                    head = tmp;
                    break;
                }
                flowerHeightList[tail]--;
            } {
                if(flowerHeightList[tail] == 0) {
                    head = tmp;
                    break;
                }
                flowerHeightList[tail]--;
            } if(flowerHeightList[tail] == 0) {
                    head = tmp;
                    break;
                } flowerHeightList[tail] == 0 flowerHeightList[tail] flowerHeightList tail 0 {
                    head = tmp;
                    break;
                } head = tmp head tmp break; flowerHeightList[tail]-- flowerHeightList[tail] flowerHeightList tail count++ count System.out.println(count) System.out.println System.out System System.out count scan.close() scan.close scan String[] args args 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();
    }

 

} 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();
    }

 

} Main
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();
    }

 

}