import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	} main {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	} try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		} {
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int []h = new int[N]; h new int[N] N int hmax = 0; hmax 0 for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			} {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			} h[i] = scan.nextInt() h[i] h i scan.nextInt() scan.nextInt scan if(hmax<h[i]) hmax = h[i]; hmax<h[i] hmax h[i] h i hmax = h[i] hmax h[i] h i int count = 0; count 0 while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			} true {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			} boolean katamari = false; katamari false for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				} {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				} if(h[i]!=0) katamari = true; h[i]!=0 h[i] h i 0 katamari = true katamari true if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					} katamari==true&&(h[i]==0||i==N-1) katamari==true katamari true (h[i]==0||i==N-1) h[i]==0 h[i] h i 0 i==N-1 i N-1 N 1 {
						count++;
						katamari = false;
					} count++ count katamari = false katamari false if(h[i]!=0)h[i]--; h[i]!=0 h[i] h i 0 h[i]-- h[i] h i int zerocount = 0; zerocount 0 for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				} {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				} if(h[i]==0)zerocount++; h[i]==0 h[i] h i 0 zerocount++ zerocount if(zerocount==N)break; zerocount==N zerocount N break; System.out.println(count) System.out.println System.out System System.out count String[]args args public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int []h = new int[N];
			int hmax = 0;
			
			for(int i = 0;i<N;i++) {
				h[i] = scan.nextInt();
				if(hmax<h[i]) hmax = h[i];
			}
			int count = 0;
			while(true) {
			
			boolean katamari = false;
			
			
				for(int i = 0;i<N;i++) {
					
					if(h[i]!=0) katamari = true;
					
					if(katamari==true&&(h[i]==0||i==N-1)){
						count++;
						katamari = false;
					}
					
					if(h[i]!=0)h[i]--;
				}
				
				int zerocount = 0;
				for(int i = 0;i<N;i++) {
					if(h[i]==0)zerocount++;
					//System.out.print(h[i]);
					//System.out.print(" ");
					
				}
				//System.out.println();
				
				if(zerocount==N)break;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

}
