import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String[] hs = br.readLine().split(" "); hs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " br.close() br.close br int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = Integer.parseInt(hs[i]);
		} {
			h[i] = Integer.parseInt(hs[i]);
		} h[i] = Integer.parseInt(hs[i]) h[i] h i Integer.parseInt(hs[i]) Integer.parseInt Integer hs[i] hs i int cnt = h[0]; cnt h[0] h 0 for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		} {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		} if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			} h[i - 1] < h[i] h[i - 1] h i - 1 i 1 h[i] h i {
				cnt += h[i] - h[i - 1];
			} cnt += h[i] - h[i - 1] cnt h[i] - h[i - 1] h[i] h i h[i - 1] h i - 1 i 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		br.close();

		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(hs[i]);
		}

		int cnt = h[0];
		for (int i = 1; i < n; i++) {
			if (h[i - 1] < h[i]) {
				cnt += h[i] - h[i - 1];
			}
		}
		System.out.println(cnt);
	}
}
