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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
} Main void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    } run {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        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[] 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 for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        } ; !end(h) end(h) end h cnt++ cnt++ cnt {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        } {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        } int l = 0 l 0 r = n; r n for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            } int j = 0; int j = 0; j 0 j < n j n j++ j++ j if (h[j] > 0) {
                l = j;
                break;
            } if (h[j] > 0) {
                l = j;
                break;
            } h[j] > 0 h[j] h j 0 {
                l = j;
                break;
            } l = j l j break; for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            } int j = l + 1; int j = l + 1; j l + 1 l 1 j < n j n j++ j++ j if (h[j] == 0) {
                r = j;
                break;
            } if (h[j] == 0) {
                r = j;
                break;
            } h[j] == 0 h[j] h j 0 {
                r = j;
                break;
            } r = j r j break; for (int j = l; j < r; j++) h[j]--; int j = l; int j = l; j l j < r j r j++ j++ j h[j]--; h[j]-- h[j] h j System.out.println(cnt) System.out.println System.out System System.out cnt boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    } end {
        return Arrays.stream(h).sum() == 0;
    } return Arrays.stream(h).sum() == 0; Arrays.stream(h).sum() == 0 Arrays.stream(h).sum() Arrays.stream(h).sum Arrays.stream(h) Arrays.stream Arrays h 0 int[] h h void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    } debug {
        System.err.println(Arrays.deepToString(os));
    } System.err.println(Arrays.deepToString(os)) System.err.println System.err System System.err Arrays.deepToString(os) Arrays.deepToString Arrays os Object... os os public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
} public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
} Main

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int cnt = 0;
        for (;!end(h); cnt++) {
            int l = 0, r = n;
            for (int j = 0; j < n; j++) if (h[j] > 0) {
                l = j;
                break;
            }
            for (int j = l + 1; j < n; j++) if (h[j] == 0) {
                r = j;
                break;
            }
            for (int j = l; j < r; j++) h[j]--;
//            debug(h);
        }

        System.out.println(cnt);
    }

    boolean end(int[] h) {
        return Arrays.stream(h).sum() == 0;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }


    public static void main(String[] args) {
        new Main().run();
    }
}
