import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    } main {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc final 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] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        } {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        } while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            } h[i] != 0 h[i] h i 0 {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            } for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                } int j = i; int j = i; j i j < N j N j++ j++ j {
                    if (h[j] == 0) break;
                    h[j]--;
                } {
                    if (h[j] == 0) break;
                    h[j]--;
                } if (h[j] == 0) break; h[j] == 0 h[j] h j 0 break; h[j]-- h[j] h j cnt++ cnt 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) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
} public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}
