import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	} main {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int[] border = new int[101]; border new int[101] 101 int[] height = new int[101]; height new int[101] 101 int answer = 0; answer 0 int count = 0; count 0 boolean flag = false; flag false int num = scan.nextInt(); num scan.nextInt() scan.nextInt scan for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		} {
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		} border[i] = scan.nextInt() border[i] border i scan.nextInt() scan.nextInt scan if(border[i] == 0) {
				count++;
			} border[i] == 0 border[i] border i 0 {
				count++;
			} count++ count border[num] = -1 border[num] border num -1 1 while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		} true {
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		} flag = false flag false for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			} int i = 0; int i = 0; i 0 i <= num i num i++ i++ i {
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			} {
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			} if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				} height[i] < border[i] height[i] height i border[i] border i {
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} height[i] += 1 height[i] height i 1 flag = true flag true if(height[i]== border[i]) {
						count++;
					} height[i]== border[i] height[i] height i border[i] border i {
						count++;
					} count++ count if(flag) {
					answer++;
					flag = false;
				} flag {
					answer++;
					flag = false;
				} answer++ answer flag = false flag false if(count == num) {
				break;
			} count == num count num {
				break;
			} break; System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] border = new int[101];
		int[] height = new int[101];
		int answer = 0;	//
		int count = 0;
		boolean flag = false;

		// input
		int num = scan.nextInt();
		for(int i = 0; i < num; i++){
			border[i] = scan.nextInt();
			if(border[i] == 0) {
				count++;
			}
		}
		border[num] = -1;

		while(true){
			flag = false;
			for(int i = 0; i <= num; i++){
				if(height[i] < border[i]){
					height[i] += 1;		// give water
					flag = true;
					if(height[i]== border[i]) {
						count++;
					}
				} else if(flag) {
					answer++;
					flag = false;
				}
			}
			if(count == num) {
				break;
			}
		}

		System.out.println(answer);


	}
}
