import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    } main {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] list = new int[n]; list new int[n] n for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int value = sc.nextInt();
            list[i] = value;
        } {
            int value = sc.nextInt();
            list[i] = value;
        } int value = sc.nextInt(); value sc.nextInt() sc.nextInt sc list[i] = value list[i] list i value int count = 0; count 0 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    }
} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            int value = sc.nextInt();
            list[i] = value;
        }

        int count = 0;
        loop : while (true) {
            boolean isStart = false;
            for (int i = 0; i < n; i++) {
                if (list[i] == 0) {
                    if (isStart) {
                        break;
                    } else if (i == n - 1){
                        break loop;
                    }
                }
                else {
                    if (!isStart) {
                        isStart = true;
                        count++;
                    }
                    list[i]--;
                }
            }
        }

        System.out.println(count);
    }
}