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