import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] h = new int[n];
		int[] hDiff = new int[n];
		int hDiffTotal = 0;
		
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		hDiff[0] = h[0];
		
		for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		}
		
		for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		}
		
		System.out.println(hDiffTotal);
	
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] h = new int[n];
		int[] hDiff = new int[n];
		int hDiffTotal = 0;
		
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		hDiff[0] = h[0];
		
		for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		}
		
		for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		}
		
		System.out.println(hDiffTotal);
	
	}
} Main public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] h = new int[n];
		int[] hDiff = new int[n];
		int hDiffTotal = 0;
		
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		hDiff[0] = h[0];
		
		for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		}
		
		for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		}
		
		System.out.println(hDiffTotal);
	
	} main {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] h = new int[n];
		int[] hDiff = new int[n];
		int hDiffTotal = 0;
		
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		hDiff[0] = h[0];
		
		for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		}
		
		for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		}
		
		System.out.println(hDiffTotal);
	
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] h = new int[n]; h new int[n] n int[] hDiff = new int[n]; hDiff new int[n] n int hDiffTotal = 0; hDiffTotal 0 for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = stdIn.nextInt();
		} {
			h[i] = stdIn.nextInt();
		} h[i] = stdIn.nextInt() h[i] h i stdIn.nextInt() stdIn.nextInt stdIn hDiff[0] = h[0] hDiff[0] hDiff 0 h[0] h 0 for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		} {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		} hDiff[i] = h[i] - h[i - 1] hDiff[i] hDiff i h[i] - h[i - 1] h[i] h i h[i - 1] h i - 1 i 1 if (hDiff[i] < 0) {
				hDiff[i] = 0;
			} hDiff[i] < 0 hDiff[i] hDiff i 0 {
				hDiff[i] = 0;
			} hDiff[i] = 0 hDiff[i] hDiff i 0 for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			hDiffTotal += hDiff[i];
		} {
			hDiffTotal += hDiff[i];
		} hDiffTotal += hDiff[i] hDiffTotal hDiff[i] hDiff i System.out.println(hDiffTotal) System.out.println System.out System System.out hDiffTotal String[] args args
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] h = new int[n];
		int[] hDiff = new int[n];
		int hDiffTotal = 0;
		
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		hDiff[0] = h[0];
		
		for (int i = 1; i < n; i++) {
			hDiff[i] = h[i] - h[i - 1];
			
			if (hDiff[i] < 0) {
				hDiff[i] = 0;
			}
			
		}
		
		for (int i = 0; i < n; i++) {
			hDiffTotal += hDiff[i];
		}
		
		System.out.println(hDiffTotal);
	
	}
}