import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner ArrayList<Integer> h = new ArrayList<>(); h new ArrayList<>() for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            h.add(scanner.nextInt());
        } {
            h.add(scanner.nextInt());
        } h.add(scanner.nextInt()) h.add h scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        } Collections.max(h)>0 Collections.max(h) Collections.max Collections h 0 {
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        } count += counter(h) count counter(h) counter h for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            } {
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            } if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                } h.get(i)>0 h.get(i) h.get h i 0 {
                    h.set(i,h.get(i)-1);
                } h.set(i,h.get(i)-1) h.set h i h.get(i)-1 h.get(i) h.get h i 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    } counter {
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    } int count = 0; count 0 for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        } int i=0; int i=0; i 0 i<num.size()-1 i num.size()-1 num.size() num.size num 1 i++ i++ i {

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        } {

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        } if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            } (num.get(i)==0)!=(num.get(i+1)==0) (num.get(i)==0) num.get(i) num.get num i 0 (num.get(i+1)==0) num.get(i+1) num.get num i+1 i 1 0 {
                count++;
            } count++ count if (num.get(0)>0) count++; num.get(0)>0 num.get(0) num.get num 0 0 count++ count if (num.get(num.size()-1)>0) count++; num.get(num.size()-1)>0 num.get(num.size()-1) num.get num num.size()-1 num.size() num.size num 1 0 count++ count count /= 2 count 2 return count; count ArrayList<Integer> num num public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

}
