import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  }
} 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(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  } main {
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt() n sc.nextInt() sc.nextInt sc res=0; res 0 int old=sc.nextInt(); old sc.nextInt() sc.nextInt sc res=old res old for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    } int i=1; int i=1; i 1 i<n i n i++ i++ i {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    } {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    } int now=sc.nextInt(); now sc.nextInt() sc.nextInt sc res+=Math.max(0, now-old) res Math.max(0, now-old) Math.max Math 0 now-old now old old=now old now System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),res=0;
    int old=sc.nextInt();
    res=old;
    for(int i=1;i<n;i++) {
    	int now=sc.nextInt();
    	res+=Math.max(0, now-old);
    	old=now;
    }
    System.out.println(res);
  }
}
