import java.util.Scanner;


public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
} Main static int N; N static int[] flowers; flowers public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	} main {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc flowers = new int[N] flowers new int[N] N for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
			 flowers[i] = sc.nextInt();
			 } {
			 flowers[i] = sc.nextInt();
			 } flowers[i] = sc.nextInt() flowers[i] flowers i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int ans = 0; ans 0 int cur = 0; cur 0 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 } int k = 0 ; int k = 0 ; k 0 k < N k N k++ k++ k {
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 } {
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 } if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 } flowers[k]>cur flowers[k] flowers k cur {
					ans += flowers[k] - cur;
				 } ans += flowers[k] - cur ans flowers[k] - cur flowers[k] flowers k cur cur = flowers[k] cur flowers[k] flowers k System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
} public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
} Main
import java.util.Scanner;


public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
}
