
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		new Main().exec();
	}

	void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {
		new Main().exec();
	}

	void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	}
} Main public static void main(String[] args) {
		new Main().exec();
	} main {
		new Main().exec();
	} new Main().exec() new Main().exec new Main() String[] args args void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	} exec {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int h[] = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
		} {
			h[i] = sc.nextInt();
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int act = 0; act 0 int result = 0; result 0 for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		} {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		} if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			} act > h[i] act h[i] h i {
				act = h[i];
			} act = h[i] act h[i] h i {
				result += h[i] - act;
				act = h[i];
			} result += h[i] - act result h[i] - act h[i] h i act act = h[i] act h[i] h i System.out.println(result) System.out.println System.out System System.out result sc.close() sc.close sc

import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		new Main().exec();
	}

	void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	}
}
