import java.util.*;
import java.lang.*;

public class Main {
    
    static int n;
    static int[] h;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    }
    
    

} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
    
    static int n;
    static int[] h;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    }
    
    

} Main static int n; n static int[] h; h public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    } main {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    } int ans = 0; ans 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc h = new int[n] h new int[n] n int[] now = new int[n]; now new int[n] n boolean end = false; end false Arrays.fill(now, 0) Arrays.fill Arrays now 0 int max = 0; max 0 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 while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        } true {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        } int l = n; l n int r = 0; r 0 for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            } {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            } if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                } now[i] != h[i] now[i] now i h[i] h i {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } if (i < l) { l = i; } i < l i l { l = i; } l = i l i if (i > r) { r = i; } i > r i r { r = i; } r = i r i {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                } if ((l == 0 && r == 0) || r != 0) {
                        break;
                    } (l == 0 && r == 0) || r != 0 (l == 0 && r == 0) l == 0 l 0 r == 0 r 0 r != 0 r 0 {
                        break;
                    } break; if (i == n - 1 && l == n && r == 0) { end = true; } i == n - 1 && l == n && r == 0 i == n - 1 && l == n && r == 0 i == n - 1 i n - 1 n 1 l == n l n r == 0 r 0 { end = true; } end = true end true if (end) { break; } end { break; } break; for (int i = l; i <= r; i++) {
                now[i] ++;
            } int i = l; int i = l; i l i <= r i r i++ i++ i {
                now[i] ++;
            } {
                now[i] ++;
            } now[i] ++ now[i] now i ans ++ ans System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {
    
    static int n;
    static int[] h;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    }
    
    

} public class Main {
    
    static int n;
    static int[] h;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    }
    
    

} Main
import java.util.*;
import java.lang.*;

public class Main {
    
    static int n;
    static int[] h;

    
    public static void main (String args[]) {
        int ans = 0;

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        h = new int[n];
        int[] now = new int[n];
        boolean end = false;
        
        Arrays.fill(now, 0);
        
        int max = 0;
        
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        while(true) {
            int l = n;
            int r = 0;
            for (int i = 0; i < n; i++) {
                if (now[i] != h[i]) {
                    if (i < l) { l = i; }
                    if (i > r) { r = i; }
                } else {
                    if ((l == 0 && r == 0) || r != 0) {
                        break;
                    }
                }
                if (i == n - 1 && l == n && r == 0) { end = true; }
            }
            if (end) { break; }
            for (int i = l; i <= r; i++) {
                now[i] ++;
            }
            ans ++;
        }


        System.out.println(ans);
    }
    
    

}