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];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		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];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		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];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int h[] = new int[N];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		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]; h new int[N] N int k[] = new int[N]; k new int[N] N boolean b[] = new boolean[N]; b new boolean[N] N int count = 0; count 0 for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			k[i] = sc.nextInt();
		} {
			k[i] = sc.nextInt();
		} k[i] = sc.nextInt() k[i] k i sc.nextInt() sc.nextInt sc int oc = 0; oc 0 while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		} true {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		} int e = oc; e oc for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			} int i = oc; int i = oc; i oc i < N i N i++ i++ i {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			} {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			} for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				} int q = oc; int q = oc; q oc q < N q N q++ q++ q {
					oc=q;
					if(h[q] != k[q])break;
				} {
					oc=q;
					if(h[q] != k[q])break;
				} oc=q oc q if(h[q] != k[q])break; h[q] != k[q] h[q] h q k[q] k q break; if(h[i] != k[i]) {
					e++;
				} h[i] != k[i] h[i] h i k[i] k i {
					e++;
				} e++ e if(h[i] == k[i]) {
					break;
				} h[i] == k[i] h[i] h i k[i] k i {
					break;
				} break; boolean w = false; w false for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			} int j = oc; int j = oc; j oc j < e j e j++ j++ j {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			} {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			} if(h[j] != k[j]) {
					w = true;
					h[j]++;
				} h[j] != k[j] h[j] h j k[j] k j {
					w = true;
					h[j]++;
				} w = true w true h[j]++ h[j] h j if(w)count++; w count++ count boolean f = true; f true for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				if(h[i] != k[i])f=false;
			} {
				if(h[i] != k[i])f=false;
			} if(h[i] != k[i])f=false; h[i] != k[i] h[i] h i k[i] k i f=false f false if(f)break; f 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){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int h[] = new int[N];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		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];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		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];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		System.out.println(count);
	}
}