import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

} Main public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	} main {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++)
			h[i] = in.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i h[i] = in.nextInt(); h[i] = in.nextInt() h[i] h i in.nextInt() in.nextInt in System.out.println(water(h, 0, n - 1)) System.out.println System.out System System.out water(h, 0, n - 1) water h 0 n - 1 n 1 String[] args args public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	} water {

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	} if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		} right < left right left return 0; 0 {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		} int min = h[left]; min h[left] h left for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]); int i = left; int i = left; i left i <= right i right i++ i++ i min = Math.min(min,	h[i]); min = Math.min(min,	h[i]) min Math.min(min,	h[i]) Math.min Math min h[i] h i for (int i = left; i <= right; i++)
				h[i] -= min; int i = left; int i = left; i left i <= right i right i++ i++ i h[i] -= min; h[i] -= min h[i] h i min for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			} int i = left; int i = left; i left i <= right i right i++ i++ i {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			} {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			} if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right); h[i] == 0 h[i] h i 0 return min + water(h, left, i - 1) + water(h, i + 1, right); min + water(h, left, i - 1) + water(h, i + 1, right) min + water(h, left, i - 1) + water(h, i + 1, right) min water(h, left, i - 1) water h left i - 1 i 1 water(h, i + 1, right) water h i + 1 i 1 right return 0; 0 int[] h h int left left int right right public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

} public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();
		
		System.out.println(water(h, 0, n - 1));		

	}
	
	public static int water(int[] h, int left, int right){

		if (right < left)
			return 0;
		else {
			int min = h[left];
			for (int i = left; i <= right; i++) 
				min = Math.min(min,	h[i]);
			for (int i = left; i <= right; i++)
				h[i] -= min;
			for (int i = left; i <= right; i++) {
				if (h[i] == 0)
					return min + water(h, left, i - 1) + water(h, i + 1, right);
			}
			
		}
		return 0;

	}

}