import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  }
}
  import java.util.*; util.* java public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  }
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  } 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 List<Integer>  index = new ArrayList<>(); index new ArrayList<>() int a = 0; a 0 for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    } {
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc if(i != 0 && h[i] <= h[i-1])
        index.add(i); i != 0 && h[i] <= h[i-1] i != 0 i 0 h[i] <= h[i-1] h[i] h i h[i-1] h i-1 i 1 index.add(i) index.add index i int sum = 0; sum 0 for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    } int i = 0; int i = 0; i 0 i < index.size() i index.size() index.size index i++ i++ i {
      sum += h[index.get(i) - 1] - h[index.get(i)];
    } {
      sum += h[index.get(i) - 1] - h[index.get(i)];
    } sum += h[index.get(i) - 1] - h[index.get(i)] sum h[index.get(i) - 1] - h[index.get(i)] h[index.get(i) - 1] h index.get(i) - 1 index.get(i) index.get index i 1 h[index.get(i)] h index.get(i) index.get index i sum += h[n - 1] sum h[n - 1] h n - 1 n 1 System.out.println(sum) System.out.println System.out System System.out sum 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];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  }
} public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    List<Integer>  index = new ArrayList<>();
    int a = 0;
    for(int i = 0;i < n;i++){
      h[i] = sc.nextInt();
      if(i != 0 && h[i] <= h[i-1])
        index.add(i);
    }
    int sum = 0;
    for(int i = 0;i < index.size();i++){
      sum += h[index.get(i) - 1] - h[index.get(i)];
    }
    sum += h[n - 1];
    System.out.println(sum);
  }
}
 