import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    }
    public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    }
    public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    }
    public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    }
    public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    }
    public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    }
    public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    }
    public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    }
    public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    } main {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] xi = new int[N]; xi new int[N] N for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            xi[i] = sc.nextInt();
        } {
            xi[i] = sc.nextInt();
        } xi[i] = sc.nextInt() xi[i] xi i sc.nextInt() sc.nextInt sc int hydrationCount = 0; hydrationCount 0 while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        } notAllZero(xi) notAllZero xi {
            hydrate(xi);
            hydrationCount++;
        } hydrate(xi) hydrate xi hydrationCount++ hydrationCount System.out.println(hydrationCount) System.out.println System.out System System.out hydrationCount String[] args args public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    } notAllZero {
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    } for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        } int i = 0; int i = 0; i 0 i < xi.length i xi.length xi xi.length i++ i++ i {
            if(xi[i] != 0) return true;
        } {
            if(xi[i] != 0) return true;
        } if(xi[i] != 0) return true; xi[i] != 0 xi[i] xi i 0 return true; true return false; false int[] xi xi public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    } hydrate {
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    } final int N = xi.length; N xi.length xi xi.length int l = 0; l 0 int r = xi.length - 1; r xi.length - 1 xi.length xi xi.length 1 l = findIndexOfL(xi, l, r) l findIndexOfL(xi, l, r) findIndexOfL xi l r r = findIndexOfR(xi, l, r) r findIndexOfR(xi, l, r) findIndexOfR xi l r for(int j = l; j <= r; j++){
            xi[j]--;
        } int j = l; int j = l; j l j <= r j r j++ j++ j {
            xi[j]--;
        } {
            xi[j]--;
        } xi[j]-- xi[j] xi j int[] xi xi public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    } findIndexOfL {
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    } for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        } int k = l; int k = l; k l k <= r k r k++ k++ k {
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        } {
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        } if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            } k < r k r {
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            } if(xi[k] == 0 && xi[k+1] != 0) return k+1; xi[k] == 0 && xi[k+1] != 0 xi[k] == 0 xi[k] xi k 0 xi[k+1] != 0 xi[k+1] xi k+1 k 1 0 return k+1; k+1 k 1 return l; l int[] xi xi int l l int r r public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    } findIndexOfR {
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    } for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        } int k = l; int k = l; k l k <= r k r k++ k++ k {
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        } {
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        } if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            } 0 < k 0 k {
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            } if(xi[k] == 0 && xi[k-1] != 0) return k-1; xi[k] == 0 && xi[k-1] != 0 xi[k] == 0 xi[k] xi k 0 xi[k-1] != 0 xi[k-1] xi k-1 k 1 0 return k-1; k-1 k 1 return r; r int[] xi xi int l l int r r public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    }
    public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    }
    public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    }
    public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    }
    public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    }
    public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    }
    public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    }
    public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    }
    public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] xi = new int[N];
        for(int i = 0; i < N; i++){
            xi[i] = sc.nextInt();
        }
        
        int hydrationCount = 0;
        while(notAllZero(xi)){
            hydrate(xi);
            hydrationCount++;
        }
        
        System.out.println(hydrationCount);
    }
    public static boolean notAllZero(int[] xi){
        for(int i = 0; i < xi.length; i++){
            if(xi[i] != 0) return true;
        }
        return false;
    }
    public static void hydrate(int[] xi){
        final int N = xi.length;
        int l = 0;
        int r = xi.length - 1;
        l = findIndexOfL(xi, l, r);
        r = findIndexOfR(xi, l, r);
        for(int j = l; j <= r; j++){
            xi[j]--;
        }
    }
    public static int findIndexOfL(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(k < r){
                if(xi[k] == 0 && xi[k+1] != 0) return k+1;
            }
        }
        return l;
    }
    public static int findIndexOfR(int[] xi, int l, int r){
        for(int k = l; k <= r; k++){
            if(0 < k){
                if(xi[k] == 0 && xi[k-1] != 0) return k-1;
            }
        }
        return r;
    }
}
