import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	} main {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	} Scanner sc = new Scanner((System.in)); sc new Scanner((System.in)) int H = sc.nextInt(); H sc.nextInt() sc.nextInt sc int[] h = new int[H + 1]; h new int[H + 1] H + 1 H 1 int sum = 0; sum 0 int c = 0; c 0 boolean t = false t false z = false; z false for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		} int i = 0; int i = 0; i 0 i < H i H i++ i++ i {
			h[i] = sc.nextInt();
			sum += h[i];
		} {
			h[i] = sc.nextInt();
			sum += h[i];
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc sum += h[i] sum h[i] h i while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		} sum > 0 sum 0 {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		} for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			} int i = 0; int i = 0; i 0 i < H i H i++ i++ i {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			} {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			} if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				} h[i] > 0 h[i] h i 0 {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} h[i]-- h[i] h i sum-- sum t = true t true z = true z true {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				} if (t) {
						c++;
						z = false;
					} t {
						c++;
						z = false;
					} c++ c z = false z false t = false t false if (z) {
				c++;
			} z {
				c++;
			} c++ c t = false t false System.out.println(c) System.out.println System.out System System.out c sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int H = sc.nextInt();
		int[] h = new int[H + 1];
		int sum = 0;
		int c = 0;
		boolean t = false, z = false;

		for (int i = 0; i < H; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}

		while (sum > 0) {
			for (int i = 0; i < H; i++) {
				if (h[i] > 0) {
					h[i]--;
					sum--;
					t = true;
					z = true;
				} else {
					if (t) {
						c++;
						z = false;
					}
					t = false;
				}
			}
			if (z) {
				c++;
			}
			t = false;
		}

		System.out.println(c);

		sc.close();
	}
}
