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];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	}
} 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];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N  = sc.nextInt();
		
		int[] h = new int[N];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		int N  = sc.nextInt();
		
		int[] h = new int[N];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	} 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]; h new int[N] N 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[] hn = new int[N]; hn new int[N] N int sum = 0; sum 0 boolean check = false; check false int count = 0; count 0 while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		} count < N count N {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		} count = 0 count 0 for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			} {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			} if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				} h[i] > hn[i] h[i] h i hn[i] hn i {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} hn[i]++ hn[i] hn i check = true check true if(i == N - 1) {
						sum++;
						check = false;
					} i == N - 1 i N - 1 N 1 {
						sum++;
						check = false;
					} sum++ sum check = false check false {
					if(check) {
						sum++;
						check = false;
					}
				} if(check) {
						sum++;
						check = false;
					} check {
						sum++;
						check = false;
					} sum++ sum check = false check false for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if(h[i] == hn[i]) {
					count++;
				}
			} {
				if(h[i] == hn[i]) {
					count++;
				}
			} if(h[i] == hn[i]) {
					count++;
				} h[i] == hn[i] h[i] h i hn[i] hn i {
					count++;
				} count++ count System.out.println(sum) System.out.println System.out System System.out sum 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];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N  = sc.nextInt();
		
		int[] h = new int[N];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	}
} 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];
		
		for(int i = 0; i < N; i++) {
			h[i] =sc.nextInt();
		}
		
		int[] hn = new int[N];
		int sum = 0;
		boolean check = false;
		int count = 0;
		
		while(count < N) {
			count = 0;
			for(int i = 0; i < N; i++) {
				if(h[i] > hn[i]) {
					hn[i]++;
					check = true;
					if(i == N - 1) {
						sum++;
						check = false;
					}
				} else {
					if(check) {
						sum++;
						check = false;
					}
				}
			}
			
			for(int i = 0; i < N; i++) {
				if(h[i] == hn[i]) {
					count++;
				}
			}
		}
		System.out.println(sum);
	}
}
