import java.util.Scanner;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  }
  
  static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  }
  
  static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  }
} Main public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  } main {
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int array[] = new int[n]; array new int[n] n for(int i = 0; i < n; i++)
      array[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i array[i] = sc.nextInt(); array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int count = 0; count 0 while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    } true {
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    } if(maxArray(array) == 0) break; maxArray(array) == 0 maxArray(array) maxArray array 0 break; int i = 0; i 0 while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      } i < n i n {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      } if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        } array[i] == 0 array[i] array i 0 i++ i {
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        } count++ count while (i < n && array[i] > 0){
            array[i]--;
            i++;
          } i < n && array[i] > 0 i < n i n array[i] > 0 array[i] array i 0 {
            array[i]--;
            i++;
          } array[i]-- array[i] array i i++ i System.out.println(count) System.out.println System.out System System.out count String[] args args static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  } maxArray {
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  } int max = 0; max 0 for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i]; int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i if(max < array[i]) max = array[i]; if(max < array[i]) max = array[i]; max < array[i] max array[i] array i max = array[i] max array[i] array i return max; max int array[] array public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  }
  
  static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  }
} public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  }
  
  static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for(int i = 0; i < n; i++)
      array[i] = sc.nextInt();
    
    
    int count = 0;
    while(true){
      if(maxArray(array) == 0) break;
      int i = 0;
      while (i < n) {
        if (array[i] == 0) i++;
        else{
          count++;
          while (i < n && array[i] > 0){
            array[i]--;
            i++;
          }
        }
      }
    }
    System.out.println(count);
  }
  
  static int maxArray(int array[]){
    int max = 0;
    for(int i = 0; i < array.length; i++)
      if(max < array[i]) max = array[i];
    return max;
  }
}