import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() 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 cnt = 0; cnt 0 int idx = 0; idx 0 int endidx = 0; endidx 0 boolean b; b while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		} true {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		} idx = 0 idx 0 b = false b false for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			} ; idx < n idx n idx++ idx++ idx {
				if (h[idx] > 0) {
					break;
				}
			} {
				if (h[idx] > 0) {
					break;
				}
			} if (h[idx] > 0) {
					break;
				} h[idx] > 0 h[idx] h idx 0 {
					break;
				} break; endidx = idx endidx idx for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			} ; endidx < n endidx n endidx++ endidx++ endidx {
				if (h[endidx] <= 0) {
					break;
				}
			} {
				if (h[endidx] <= 0) {
					break;
				}
			} if (h[endidx] <= 0) {
					break;
				} h[endidx] <= 0 h[endidx] h endidx 0 {
					break;
				} break; for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			} ; idx < endidx idx endidx idx++ idx++ idx {
				h[idx]--;
				b = true;
			} {
				h[idx]--;
				b = true;
			} h[idx]-- h[idx] h idx b = true b true if (b) {
				cnt++;
			} else {
				break;
			} b {
				cnt++;
			} cnt++ cnt {
				break;
			} break; 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) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int cnt = 0;
		int idx = 0;
		int endidx = 0;
		boolean b;
		while (true) {
			idx = 0;
			b = false;
			for (; idx < n; idx++) {
				if (h[idx] > 0) {
					break;
				}
			}
			endidx = idx;
			for (; endidx < n; endidx++) {
				if (h[endidx] <= 0) {
					break;
				}
			}
			for (; idx < endidx; idx++) {
				h[idx]--;
				b = true;
			}
			if (b) {
				cnt++;
			} else {
				break;
			}
		}
		System.out.println(cnt);
	}
}
