import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int[] as = new int[n];
	        int answer = 0;
	        for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        }
	        
	        System.out.print(answer);
	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int[] as = new int[n];
	        int answer = 0;
	        for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        }
	        
	        System.out.print(answer);
	}
} Main public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int[] as = new int[n];
	        int answer = 0;
	        for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        }
	        
	        System.out.print(answer);
	} main {
		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int[] as = new int[n];
	        int answer = 0;
	        for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        }
	        
	        System.out.print(answer);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] as = new int[n]; as new int[n] n int answer = 0; answer 0 for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        } {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        } as[i] = sc.nextInt() as[i] as i sc.nextInt() sc.nextInt sc if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]); i==0 i 0 answer = as[0] answer as[0] as 0 answer += Math.max(0, as[i] - as[i-1]) answer Math.max(0, as[i] - as[i-1]) Math.max Math 0 as[i] - as[i-1] as[i] as i as[i-1] as i-1 i 1 System.out.print(answer) System.out.print System.out System System.out answer String args[] args
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		 Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        int[] as = new int[n];
	        int answer = 0;
	        for (int i = 0; i < n; i++) {
	            as[i] = sc.nextInt();
	            if(i==0)
	            	answer = as[0];
	            else
	            	answer += Math.max(0, as[i] - as[i-1]);
	        }
	        
	        System.out.print(answer);
	}
}