import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] s = new int[n]; s new int[n] n int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) h[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i h[i] = sc.nextInt(); h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 boolean flag = false; flag false while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        } true {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        } flag = false flag false for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            } {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            } if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                } s[i] != h[i] s[i] s i h[i] h i {
                    s[i] += 1;
                    flag = true;
                } s[i] += 1 s[i] s i 1 flag = true flag true if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                } s[i] == h[i] && flag s[i] == h[i] s[i] s i h[i] h i flag {
                    cnt += 1;
                    flag = false;

                } cnt += 1 cnt 1 flag = false flag false if (flag) cnt += 1; flag cnt += 1 cnt 1 if (Arrays.equals(s, h)) break; Arrays.equals(s, h) Arrays.equals Arrays s h break; System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();

        int cnt = 0;
        boolean flag = false;

        while (true) {
            flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] != h[i]) {
                    s[i] += 1;
                    flag = true;
                } else if (s[i] == h[i] && flag) {
                    cnt += 1;
                    flag = false;

                }
            }
            if (flag) cnt += 1;
            if (Arrays.equals(s, h)) break;
        }
        System.out.println(cnt);
    }
}
