import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

} Main public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	} main {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	} final Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) final int counter = scanner.nextInt(); counter scanner.nextInt() scanner.nextInt scanner final int[] array = new int[counter]; array new int[counter] counter for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < counter i counter i++ i++ i {
			array[i] = scanner.nextInt();
		} {
			array[i] = scanner.nextInt();
		} array[i] = scanner.nextInt() array[i] array i scanner.nextInt() scanner.nextInt scanner int result = 0; result 0 while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		} isLoopContinue(array) isLoopContinue array {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		} boolean bool = false; bool false for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			} int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			} {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			} if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				} array[i] > 0 array[i] array i 0 {
					bool = true;
					array[i]--;
				} bool = true bool true array[i]-- array[i] array i {
					if (bool) {
						bool = false;
						result++;
					}
				} if (bool) {
						bool = false;
						result++;
					} bool {
						bool = false;
						result++;
					} bool = false bool false result++ result if (bool) {
				result++;
			} bool {
				result++;
			} result++ result System.out.println(result) System.out.println System.out System System.out result scanner.close() scanner.close scanner String[] args args public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	} isLoopContinue {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	} for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		} int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
			if (array[i] > 0) {
				return true;
			}
		} {
			if (array[i] > 0) {
				return true;
			}
		} if (array[i] > 0) {
				return true;
			} array[i] > 0 array[i] array i 0 {
				return true;
			} return true; true return false; false final int[] array array public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

} public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int[] array = new int[counter];

		for (int i = 0; i < counter; i++) {
			array[i] = scanner.nextInt();
		}

		int result = 0;
		while (isLoopContinue(array)) {
			boolean bool = false;
			for (int i = 0; i < array.length; i++) {
				if (array[i] > 0) {
					bool = true;
					array[i]--;
				} else {
					if (bool) {
						bool = false;
						result++;
					}
				}
			}
			if (bool) {
				result++;
			}
		}
		System.out.println(result);
		scanner.close();
	}

	public static boolean isLoopContinue(final int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 0) {
				return true;
			}
		}

		return false;
	}

}
