import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) C solver = new C(); solver new C() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    } C public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        } solve {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        } int n = Integer.parseInt(in.next()); n Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int h[] = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                h[i] = Integer.parseInt(in.next());
            } {
                h[i] = Integer.parseInt(in.next());
            } h[i] = Integer.parseInt(in.next()) h[i] h i Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int ans = 0; ans 0 while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            } true {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            } if (arrmax(h) == 0) break; arrmax(h) == 0 arrmax(h) arrmax h 0 break; int i = 0; i 0 while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                } i < n i n {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                } if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    } h[i] == 0 h[i] h i 0 {
                        ++i;
                    } ++i i {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    } ++ans ans while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        } i < n && h[i] > 0 i < n i n h[i] > 0 h[i] h i 0 {
                            --h[i];
                            ++i;
                        } --h[i] h[i] h i ++i i out.println(ans) out.println out ans int testNumber testNumber Scanner in in PrintWriter out out public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        } arrmax {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        } int max = -1; max -1 1 int res[] = new int[arr.length]; res new int[arr.length] arr.length arr arr.length for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            } int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {   //(6)
                res[i] = arr[i];
            } {   //(6)
                res[i] = arr[i];
            } res[i] = arr[i] res[i] res i arr[i] arr i Arrays.sort(res) Arrays.sort Arrays res return res[res.length - 1]; res[res.length - 1] res res.length - 1 res.length res res.length 1 int[] arr arr public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            while (true) {
                if (arrmax(h) == 0) break;
                int i = 0;
                while (i < n) {
                    if (h[i] == 0) {
                        ++i;
                    } else {
                        ++ans;
                        while (i < n && h[i] > 0) {
                            --h[i];
                            ++i;
                        }
                    }
                }
            }

            // 出力
            out.println(ans);

        }

        public static int arrmax(int[] arr) {
            int max = -1;
            int res[] = new int[arr.length];
            for (int i = 0; i < arr.length; i++) {   //(6)
                res[i] = arr[i];
            }
            Arrays.sort(res);
            return res[res.length - 1];
//        for (int i = 1; i < arr.length; i++) {
//            int v = arr[i];
//            if (v > max) {
//                max = v;
//            }
//        }
//        return max;
        }

    }
}

