import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] height = new int[n]; height new int[n] n for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			height[i] = sc.nextInt();
		} {
			height[i] = sc.nextInt();
		} height[i] = sc.nextInt() height[i] height i sc.nextInt() sc.nextInt sc int[] allzero = new int[n]; allzero new int[n] n Arrays.fill(allzero, 0) Arrays.fill Arrays allzero 0 int count = 0; count 0 while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		} true {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		} if(Arrays.equals(height, allzero)) {
				break;
			} Arrays.equals(height, allzero) Arrays.equals Arrays height allzero {
				break;
			} break; for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			} {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			} int f = height[i]; f height[i] height i if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				} f > 0 f 0 {
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				} try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					} catch (Exception e){
						count++;
					} Exception e {
						count++;
					} count++ count {
						if(height[i + 1] == 0){
							count++;
						}
					} if(height[i + 1] == 0){
							count++;
						} height[i + 1] == 0 height[i + 1] height i + 1 i 1 0 {
							count++;
						} count++ count height[i]-- height[i] height i {
					continue;
				} continue; 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 = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
} public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int[] height = new int[n];
		
		
		for(int i = 0; i < n; i++) {
			height[i] = sc.nextInt();
		}
		
		int[] allzero = new int[n];
		Arrays.fill(allzero, 0);
		
		int count = 0;
		while(true) {
			
			if(Arrays.equals(height, allzero)) {
				break;
			}
			
			for(int i = 0; i < n; i++) {
				int f = height[i];
				
				if(f > 0){
					try{
						if(height[i + 1] == 0){
							count++;
						}
					}catch (Exception e){
						count++;
					}
					
					height[i]--;
				}else{
					continue;
				}
			}
		}
		System.out.println(count);
	}
}