

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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = Integer.parseInt(sc.next());
		} {
			h[i] = Integer.parseInt(sc.next());
		} h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ans = 0; ans 0 int act = 0; act 0 for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += 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 {
				ans += h[i] - act;
				act = h[i];
			}
		} {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = h[i];
			}
		} if (act >= h[i]) {
				act = h[i];
			} else {
				ans += 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 {
				ans += h[i] - act;
				act = h[i];
			} ans += h[i] - act ans h[i] - act h[i] h i act act = h[i] act 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = 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] = Integer.parseInt(sc.next());
		}

		int ans = 0;
		int act = 0;

		for (int i = 0; i < n; i++) {
			if (act >= h[i]) {
				act = h[i];
			} else {
				ans += h[i] - act;
				act = h[i];
			}
		}
		System.out.println(ans);
	}

}
