import java.util.*;
import static java.lang.Math.*;

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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; 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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} 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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    } 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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    } 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 res = 0; res 0 while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        } true {
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        } int max = 0; max 0 for(int i=0; i<n; i++){
                max = max(max,h[i]);
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
                max = max(max,h[i]);
            } {
                max = max(max,h[i]);
            } max = max(max,h[i]) max max(max,h[i]) max max h[i] h i if(max == 0) break; max == 0 max 0 break; int j = 0; j 0 while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            } j<n j n {
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            } if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                } h[j]==0 h[j] h j 0 j++ j {
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                } res++ res while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    } j < n && h[j] > 0 j < n j n h[j] > 0 h[j] h j 0 {
                        --h[j];
                        j++;
                    } --h[j] h[j] h j j++ j System.out.println(res) System.out.println System.out System System.out res 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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} 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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
} Main
import java.util.*;
import static java.lang.Math.*;

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 res = 0;
        while(true){
            int max = 0;
            for(int i=0; i<n; i++){
                max = max(max,h[i]);
            }
            if(max == 0) break;

            int j = 0;
            while(j<n){
                if(h[j]==0) j++;
                else{
                    res++;
                    while(j < n && h[j] > 0){
                        --h[j];
                        j++;
                    }
                }
            }
        }
        System.out.println(res);
    }
}