import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int []h = new int [n+1]; h new int [n+1] n+1 n 1 for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
		} {
			h[i] = sc.nextInt();
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int r r l; l int count = 0; count 0 do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0); r != 0 || l != 0 r != 0 r 0 l != 0 l 0 {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		} r = 0 r 0 l = 0 l 0 int flag = 0; flag 0 for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			} int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			} {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			} if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				} h[i] > 0 && flag == 0 h[i] > 0 h[i] h i 0 flag == 0 flag 0 {
					flag = 1;
					count++;					
					r = i;
				} flag = 1 flag 1 count++ count r = i r i if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				} h[i] == 0 && flag == 1 h[i] == 0 h[i] h i 0 flag == 1 flag 1 {
					flag = 0; 
					l = i;
					break;
				} flag = 0 flag 0 l = i l i break; for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			} int i = r; int i = r; i r i < l i l i++ i++ i {
				h[i] = h[i] - 1;
			} {
				h[i] = h[i] - 1;
			} h[i] = h[i] - 1 h[i] h i h[i] - 1 h[i] h i 1 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) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int []h = new int [n+1];
		
		for(int i = 0; i < n ; i++) {
			h[i] = sc.nextInt();
		}
		int r , l;
		int count = 0;
		do {
			r = 0; l = 0;
			int flag = 0;
			for(int i = 0; i <= n ; i++) {
				if(h[i] > 0 && flag == 0) {
					flag = 1;
					count++;					
					r = i;
				}
				if(h[i] == 0 && flag == 1) {
					flag = 0; 
					l = i;
					break;
				}
			}
			
			for(int i = r; i < l ; i++) {
				h[i] = h[i] - 1;
			}
			
		}while(r != 0 || l != 0);
		
		System.out.println(count);
	} 		
}


