

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	} main {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		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 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 count = 0; count 0 while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		} true {
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		} int start = -1; start -1 1 for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(h[i] != 0){
					start = i;
					break;
				}
			} {
				if(h[i] != 0){
					start = i;
					break;
				}
			} if(h[i] != 0){
					start = i;
					break;
				} h[i] != 0 h[i] h i 0 {
					start = i;
					break;
				} start = i start i break; if(start < 0){
				break;
			} start < 0 start 0 {
				break;
			} break; count++ count for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			} int i = start; int i = start; i start i < n i n i++ i++ i {
				if(h[i] == 0){
					break;
				}

				h[i]--;
			} {
				if(h[i] == 0){
					break;
				}

				h[i]--;
			} if(h[i] == 0){
					break;
				} h[i] == 0 h[i] h i 0 {
					break;
				} break; h[i]-- h[i] h i 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) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	}
} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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 count = 0;;
		while(true){
			//0じゃないところを探す
			int start = -1;
			for(int i = 0; i < n; i++){
				if(h[i] != 0){
					start = i;
					break;
				}
			}

			if(start < 0){
				break;
			}

			count++;

			for(int i = start; i < n; i++){
				if(h[i] == 0){
					break;
				}

				h[i]--;
			}
		}

		System.out.println(count);
	}
}
