
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			h[i] = in.nextInt();
		} {
			h[i] = in.nextInt();
		} h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in int ans = 0; ans 0 while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		} true {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		} int left = -1; left -1 1 for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if (h[i] != 0) {
					left = i;
					break;
				}
			} {
				if (h[i] != 0) {
					left = i;
					break;
				}
			} if (h[i] != 0) {
					left = i;
					break;
				} h[i] != 0 h[i] h i 0 {
					left = i;
					break;
				} left = i left i break; if (left == -1) {
				break;
			} left == -1 left -1 1 {
				break;
			} break; int i = left; i left while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			} i < N i N {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			} if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				} h[i] == 0 h[i] h i 0 ++i i {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				} ++ans ans 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(ans) System.out.println System.out System System.out ans in.close() in.close in String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = in.nextInt();
		}
		int ans = 0;
		while (true) {
			int left = -1;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					left = i;
					break;
				}
			}
			if (left == -1) {
				break;
			}
			int i = left;
			while (i < N) {
				if (h[i] == 0)
					++i;
				else {
					++ans;
					while (i < N && h[i] > 0) {
						--h[i];
						++i;
					}
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
}