import java.util.Scanner;


public class Main {

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int max =0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			if (A[i]>max) {
				max = A[i];
			}
		}
		int count =0;
		for (int i=0;i<max;i++) {
			int temp =0;
			while (temp<N) {
				boolean b = false;
				for (;temp<N;temp++) {
					if (A[temp]>0) {
						A[temp]--;
						b = true;
					} else if (b){
						break;
					}
				}
				if (b==true)
					count++;
			}
		}
		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 A[] = new int[N];
		int max =0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			if (A[i]>max) {
				max = A[i];
			}
		}
		int count =0;
		for (int i=0;i<max;i++) {
			int temp =0;
			while (temp<N) {
				boolean b = false;
				for (;temp<N;temp++) {
					if (A[temp]>0) {
						A[temp]--;
						b = true;
					} else if (b){
						break;
					}
				}
				if (b==true)
					count++;
			}
		}
		System.out.println(count);
	}
}