import java.util.*;

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;
    for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java 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;
    for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    }
    System.out.println(ans);
  }
} 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;
    for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    }
    System.out.println(ans);
  } 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;
    for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    }
    System.out.println(ans);
  } 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 for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    } int i=100; int i=100; i 100 i>0 i 0 i-- i-- i {
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    } {
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    } boolean living=false; living false for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      } int j=0; int j=0; j 0 j<n j n j++ j++ j {
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      } {
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      } if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        } h[j]>=i h[j] h j i {
          if(!living){
            living=true;
            ans++;
          }
        } if(!living){
            living=true;
            ans++;
          } !living living {
            living=true;
            ans++;
          } living=true living true ans++ ans {
          living=false;
        } living=false living false System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

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;
    for(int i=100;i>0;i--){
      boolean living=false;
      for(int j=0;j<n;j++){
        if(h[j]>=i){
          if(!living){
            living=true;
            ans++;
          }
        }else{
          living=false;
        }
      }
    }
    System.out.println(ans);
  }
}
