import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
} Main public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    } main {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    } 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] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int ans = 0; ans 0 while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        } true {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        } boolean flg = true; flg true int count = 0; count 0 for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            } {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            } if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                } h[i] != 0 && flg h[i] != 0 h[i] h i 0 flg {
                    ans++;
                    flg = false;
                } ans++ ans flg = false flg false if(h[i] == 0){
                    flg = true;
                    count++;
                } h[i] == 0 h[i] h i 0 {
                    flg = true;
                    count++;
                } flg = true flg true count++ count if(h[i] > 0) {
                    h[i]--;
                } h[i] > 0 h[i] h i 0 {
                    h[i]--;
                } h[i]-- h[i] h i if(count == n) {
                    System.out.println(ans);
                    return;
                } count == n count n {
                    System.out.println(ans);
                    return;
                } System.out.println(ans) System.out.println System.out System System.out ans return; String[] args args public class Main {
    public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        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 ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
}