import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
}
 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.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);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
} 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);
        GrandGarden solver = new GrandGarden();
        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);
        GrandGarden solver = new GrandGarden();
        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) GrandGarden solver = new GrandGarden(); solver new GrandGarden() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    } GrandGarden public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        } solve {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                h[i] = in.nextInt();
            } {
                h[i] = in.nextInt();
            } h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in long result = 0; result 0 int i = 0; i 0 while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            } i < n i n {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            } if (h[i] == 0) {
                    i++;
                    continue;
                } h[i] == 0 h[i] h i 0 {
                    i++;
                    continue;
                } i++ i continue; int v = 1; v 1 result += 1 result 1 h[i] -= v h[i] h i v for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                } {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                } if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    } h[j] > 0 h[j] h j 0 {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } h[j] = (h[j] >= v) ? h[j] - v : 0 h[j] h j (h[j] >= v) ? h[j] - v : 0 (h[j] >= v) h[j] h j v h[j] - v h[j] h j v 0 {
                        break;
                    } break; out.print(result) out.print out result int testNumber testNumber Scanner in in PrintWriter out out 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);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
} 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);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        GrandGarden solver = new GrandGarden();
        solver.solve(1, in, out);
        out.close();
    }

    static class GrandGarden {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = in.nextInt();
            }

            long result = 0;
            int i = 0;
            while (i < n) {
                if (h[i] == 0) {
                    i++;
                    continue;
                }
                int v = 1;
                result += 1;
                h[i] -= v;
                for (int j = i + 1; j < n; j++) {
                    if (h[j] > 0) {
                        h[j] = (h[j] >= v) ? h[j] - v : 0;
                    } else {
                        break;
                    }
                }
            }
            out.print(result);
        }

    }
}

