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 = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  }
} 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 = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  }
} 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 = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  } 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 = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  } 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] H i sc.nextInt() sc.nextInt sc int ans = H[0] + H[N-1]; ans H[0] + H[N-1] H[0] H 0 H[N-1] H N-1 N 1 for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]); int i=1; int i=1; i 1 i<N i N i++ i++ i ans += Math.abs(H[i-1]-H[i]); ans += Math.abs(H[i-1]-H[i]) ans Math.abs(H[i-1]-H[i]) Math.abs Math H[i-1]-H[i] H[i-1] H i-1 i 1 H[i] H i System.out.println(ans/2) System.out.println System.out System System.out ans/2 ans 2 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 = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  }
}