import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	}
}
 import java.util.*; util.* java import java.math.*; math.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			list.add(sc.nextInt());
		} {
			list.add(sc.nextInt());
		} list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc int count = 0; count 0 boolean isAllZero =false; isAllZero false for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		} int i=0; int i=0; i 0 i<101 i 101 i++ i++ i {
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		} {
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		} count++ count boolean flag =false; flag false isAllZero =true isAllZero true boolean isAfterSecondZero =false; isAfterSecondZero false for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			} int j =0; int j =0; j 0 j<n j n j++ j++ j {
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			} {
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			} int height = list.get(j); height list.get(j) list.get list j if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				} height == 0 height 0 {
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				} if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					} isAfterSecondZero {
						flag =true;
						// isAfterSecondZero =false;
					} flag =true flag true {
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				} isAfterSecondZero =true isAfterSecondZero true isAllZero =false isAllZero false list.set(j,height-1) list.set list j height-1 height 1 if(flag){
						count++;
					} flag {
						count++;
					} count++ count flag =false flag false if(isAllZero){
				break;
			} isAllZero {
				break;
			} break; System.out.println(count-1) System.out.println System.out System System.out count-1 count 1 String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	}
} Main
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i=0;i<n;i++){
			list.add(sc.nextInt());
		}
		int count = 0;

		boolean isAllZero =false;
		for(int i=0;i<101;i++){
			count++;
			boolean flag =false;
			isAllZero =true;
			boolean isAfterSecondZero =false;
			for(int j =0;j<n;j++){
				int height = list.get(j);
				if(height == 0 ){
					if(isAfterSecondZero){
						flag =true;
						// isAfterSecondZero =false;
					}
				}else{
					isAfterSecondZero =true;
					isAllZero =false;
					list.set(j,height-1);
					if(flag){
						count++;
					}
					flag =false;
				}
				// System.out.print("j"+j);
				// System.out.print(" height"+height);
				// System.out.println(" count"+count);
			}
			if(isAllZero){
				break;
			}
			// if(i >50){
			// 	System.out.print(i + " ");
			// 	System.out.print(count);
			// 	System.out.println(" end oneLine");

			// }

		}
		System.out.println(count-1);

	}
}

