
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = Integer.parseInt(scan.next()); N Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			h[i] = Integer.parseInt(scan.next());
		} {
			h[i] = Integer.parseInt(scan.next());
		} h[i] = Integer.parseInt(scan.next()) h[i] h i Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int count = 0; count 0 boolean find; find while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		} true {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		} find = false find false for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			} {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			} if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				} h[i] != 0 h[i] h i 0 {
					find = true;
					h[i]--;
				} find = true find true h[i]-- h[i] h i if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				} find && i != N - 1 find i != N - 1 i N - 1 N 1 {
					break;
				} break; if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				} !find && i != N - 1 !find find i != N - 1 i N - 1 N 1 {
					continue;
				} continue; if (!find && i == N - 1) {
					System.out.println(count);
					return;
				} !find && i == N - 1 !find find i == N - 1 i N - 1 N 1 {
					System.out.println(count);
					return;
				} System.out.println(count) System.out.println System.out System System.out count return; count++ count String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = Integer.parseInt(scan.next());
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(scan.next());
		}
		int count = 0;
		boolean find;
		while (true) {
			find = false;
			for (int i = 0; i < N; i++) {
				if (h[i] != 0) {
					find = true;
					h[i]--;
				} else if (find && i != N - 1) {
					break;
				} else if (!find && i != N - 1) {
					continue;
				} else if (!find && i == N - 1) {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
	}
}
