import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

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

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	} main {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int totalFlower = scanner.nextInt(); totalFlower scanner.nextInt() scanner.nextInt scanner int flowersHeight[] = new int[totalFlower]; flowersHeight new int[totalFlower] totalFlower for(int i = 0; i < totalFlower; ++i) {
			flowersHeight[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < totalFlower i totalFlower ++i ++i i {
			flowersHeight[i] = scanner.nextInt();
		} {
			flowersHeight[i] = scanner.nextInt();
		} flowersHeight[i] = scanner.nextInt() flowersHeight[i] flowersHeight i scanner.nextInt() scanner.nextInt scanner int wateringTimes = 0; wateringTimes 0 System.out.print(wateringTimes) System.out.print System.out System System.out wateringTimes scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

} public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];

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

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);

		scanner.close();
	}

}
