import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


} import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


} Main static int count = 0; count 0 static int heights[]; heights public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc heights = new int[n] heights new int[n] n for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            heights[i] = sc.nextInt();
        } {
            heights[i] = sc.nextInt();
        } heights[i] = sc.nextInt() heights[i] heights i sc.nextInt() sc.nextInt sc while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        } true {

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        } int sum = 0; sum 0 for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            } int i = 0; int i = 0; i 0 i < heights.length i heights.length heights heights.length i++ i++ i {
                sum += heights[i];
            } {
                sum += heights[i];
            } sum += heights[i] sum heights[i] heights i if(sum == 0){
                System.out.println(count);
                break;
            } sum == 0 sum 0 {
                System.out.println(count);
                break;
            } System.out.println(count) System.out.println System.out System System.out count break; reduceHeight(heights) reduceHeight heights String args[] args private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    } reduceHeight {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    } int min = 0; min 0 int max = heights.length; max heights.length heights heights.length for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        } int i = 0; int i = 0; i 0 i < heights.length i heights.length heights heights.length i++ i++ i {
            if(heights[i] > 0){
                min = i;
                break;
            }
        } {
            if(heights[i] > 0){
                min = i;
                break;
            }
        } if(heights[i] > 0){
                min = i;
                break;
            } heights[i] > 0 heights[i] heights i 0 {
                min = i;
                break;
            } min = i min i break; for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        } int i = min; int i = min; i min i < heights.length i heights.length heights heights.length i++ i++ i {
            if(heights[i] == 0){
                max = i;
                break;
            }
        } {
            if(heights[i] == 0){
                max = i;
                break;
            }
        } if(heights[i] == 0){
                max = i;
                break;
            } heights[i] == 0 heights[i] heights i 0 {
                max = i;
                break;
            } max = i max i break; for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        } int i = min; int i = min; i min i < max i max i++ i++ i {
            heights[i] = heights[i] - 1;
        } {
            heights[i] = heights[i] - 1;
        } heights[i] = heights[i] - 1 heights[i] heights i heights[i] - 1 heights[i] heights i 1 count++ count int[] heights heights public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


} public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


}