import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] h = new int[N + 2]; h new int[N + 2] N + 2 N 2 for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i < h.length - 1 i h.length - 1 h.length h h.length 1 i++ i++ i {
            h[i] = sc.nextInt();
        } {
            h[i] = sc.nextInt();
        } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int counter = 0; counter 0 int[] check = new int[h.length]; check new int[h.length] h.length h h.length while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        } !Arrays.equals(h, check) Arrays.equals(h, check) Arrays.equals Arrays h check {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        } int m = 0; m 0 for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            } int i = 1; int i = 1; i 1 i < h.length - 1 i h.length - 1 h.length h h.length 1 i++ i++ i {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            } {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            } if (m == 0 && h[i] != 0) {
                    counter++;
                } m == 0 && h[i] != 0 m == 0 m 0 h[i] != 0 h[i] h i 0 {
                    counter++;
                } counter++ counter m = h[i] m h[i] h i if (h[i] != 0) {
                    h[i]--;
                } h[i] != 0 h[i] h i 0 {
                    h[i]--;
                } h[i]-- h[i] h i System.out.println(counter) System.out.println System.out System System.out counter sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N + 2];
        for (int i = 1; i < h.length - 1; i++) {
            h[i] = sc.nextInt();
        }
        int counter = 0;
        int[] check = new int[h.length];
        while (!Arrays.equals(h, check)) {
            int m = 0;
            for (int i = 1; i < h.length - 1; i++) {
                if (m == 0 && h[i] != 0) {
                    counter++;
                }
                m = h[i];
                if (h[i] != 0) {
                    h[i]--;
                }
            }
        }
        System.out.println(counter);
        sc.close();
    }
}