import java.util.*;
public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
} import java.util.*; util.* java public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc static int[] h = new int[n]; h new int[n] n public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    } main {
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,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] h i sc.nextInt() sc.nextInt sc System.out.println(div(1,n)) System.out.println System.out System System.out div(1,n) div 1 n String[] args args public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    } div {
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    } if(y==x) return h[x-1]; y==x y x return h[x-1]; h[x-1] h x-1 x 1 if(y < x) return 0; y < x y x return 0; 0 int min = 10000000; min 10000000 for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      } int i = x; int i = x; i x i <= y i y i++ i++ i {
      	min = Math.min(min,h[i-1]);
      } {
      	min = Math.min(min,h[i-1]);
      } min = Math.min(min,h[i-1]) min Math.min(min,h[i-1]) Math.min Math min h[i-1] h i-1 i 1 for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      } int i = x; int i = x; i x i <= y i y i++ i++ i {
      	h[i-1]-=min;
      } {
      	h[i-1]-=min;
      } h[i-1]-=min h[i-1] h i-1 i 1 min for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      } int i = x; int i = x; i x i <= y i y i++ i++ i {
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      } {
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      } if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min; h[i-1]==0 h[i-1] h i-1 i 1 0 return div(x,i-1)+div(i+1,y)+min; div(x,i-1)+div(i+1,y)+min div(x,i-1)+div(i+1,y)+min div(x,i-1) div x i-1 i 1 div(i+1,y) div i+1 i 1 y min return 0; 0 int x x int y y public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
} public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
} Main
import java.util.*;
public class Main{
    static Scanner sc = new Scanner(System.in);
      static int n = sc.nextInt();
      static int[] h = new int[n];
    public static void main(String[] args){
      for(int i = 0;i < n;i++)h[i]=sc.nextInt();
      System.out.println(div(1,n));
    }
    public static int div(int x,int y){
      if(y==x) return h[x-1];
      if(y < x) return 0;
      int min = 10000000;
      for(int i = x;i <= y;i++){
      	min = Math.min(min,h[i-1]);
      }
      for(int i = x;i <= y;i++){
      	h[i-1]-=min;
      }
      for(int i = x;i <= y;i++){
      	if(h[i-1]==0)return div(x,i-1)+div(i+1,y)+min;
      }
      return 0;
    }
}