import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    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 ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    System.out.println(ans);
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    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 ple=sc.nextInt(); ple sc.nextInt() sc.nextInt sc int ans=ple; ans ple int cur; cur for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    } int i=1; int i=1; i 1 i<n i n i++ i++ i {
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    } {
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    } cur=sc.nextInt() cur sc.nextInt() sc.nextInt sc ans+=Integer.max(cur-ple,0) ans Integer.max(cur-ple,0) Integer.max Integer cur-ple cur ple 0 ple=cur ple cur 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 ple=sc.nextInt();
    int ans=ple;
    int cur;
    for(int i=1;i<n;i++){
      cur=sc.nextInt();
      ans+=Integer.max(cur-ple,0);
      ple=cur;
    }
    System.out.println(ans);
  }
}