import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.HashSet; HashSet java.util import java.util.Set; Set java.util public class Main {

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

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	} 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 int h[] = new int[n]; h new int[n] n String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(str[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = Integer.parseInt(str[i]);
		} {
			h[i] = Integer.parseInt(str[i]);
		} h[i] = Integer.parseInt(str[i]) h[i] h i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int res = 0; res 0 while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		} true {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		} int max = 0; max 0 for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				max = Math.max(max, h[i]);
			} {
				max = Math.max(max, h[i]);
			} max = Math.max(max, h[i]) max Math.max(max, h[i]) Math.max Math max h[i] h i if (max == 0)
				break; max == 0 max 0 break; int i = 0; i 0 while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			} i < n i n {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			} if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				} h[i] == 0 h[i] h i 0 {
					++i;
				} ++i i {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				} ++res res while (i < n && h[i] > 0) {
						--h[i];
						++i;
					} i < n && h[i] > 0 i < n i n h[i] > 0 h[i] h i 0 {
						--h[i];
						++i;
					} --h[i] h[i] h i ++i i System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {

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

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
} public class Main {

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

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

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

		int n = Integer.parseInt(br.readLine());

		int h[] = new int[n];
		String str[] = br.readLine().split(" ");

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

		int res = 0;
		while (true) {
			int max = 0;
			for (int i = 0; i < n; i++) {
				max = Math.max(max, h[i]);
			}
			if (max == 0)
				break;

			int i = 0;
			while (i < n) {
				if (h[i] == 0) {
					++i;
				} else {
					++res;
					while (i < n && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(res);
	}
}
