import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {


	public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	} main {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	} 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 ans = 0; ans 0 int active = 0; active 0 for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		} {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		} if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			} active >= h[i] active h[i] h i {
				active = h[i];
			} active = h[i] active h[i] h i {
				ans += h[i] - active;
				active = h[i];
			} ans += h[i] - active ans h[i] - active h[i] h i active active = h[i] active h[i] h i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {


	public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	}
} public class Main {


	public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		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 ans = 0;
		int active = 0;
		for (int i = 0; i < N; i++) {
			if (active >= h[i]) {
				active = h[i];
			} else {
				ans += h[i] - active;
				active = h[i];
			}
		}

		System.out.println(ans);
	}
}