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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	}
} 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	}
} 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	} 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	} 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] h i sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		} int interval = N; int interval = N; interval N interval >= 1 interval 1 interval-- interval-- interval {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		} {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		} for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			} int i = 0; int i = 0; i 0 i + interval - 1 < N i + interval - 1 i + interval i interval 1 N i++ i++ i {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			} {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			} int j = i + interval - 1; j i + interval - 1 i + interval i interval 1 int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int k = i; k<=j; k++) min = Math.min(min, h[k]); int k = i; int k = i; k i k<=j k j k++ k++ k min = Math.min(min, h[k]); min = Math.min(min, h[k]) min Math.min(min, h[k]) Math.min Math min h[k] h k if(min == 0) continue; min == 0 min 0 continue; for(int k = i; k<=j; k++) {
					h[k] -= min;
				} int k = i; int k = i; k i k<=j k j k++ k++ k {
					h[k] -= min;
				} {
					h[k] -= min;
				} h[k] -= min h[k] h k min ans += min ans min System.out.println(ans) System.out.println System.out System System.out ans 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	}
} 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	}
} 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 ans = 0;
		for(int interval = N; interval >= 1; interval--) {
			for(int i = 0; i + interval - 1 < N; i++) {
				int j = i + interval - 1;
				int min = Integer.MAX_VALUE;
				for(int k = i; k<=j; k++) min = Math.min(min, h[k]);
				if(min == 0) continue;
				for(int k = i; k<=j; k++) {
					h[k] -= min;
				}
				ans += min;
			}
		}
		System.out.println(ans);
	}
}
