import java.util.*;

class Main{
	static int[] nums;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	}

	static public int divZero(int start, int end){
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	}
} import java.util.*; util.* java class Main{
	static int[] nums;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	}

	static public int divZero(int start, int end){
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	}
} Main static int[] nums; nums public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc nums = new int[num] nums new int[num] num for(int i = 0; i < num; i++)nums[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < num i num i++ i++ i nums[i] = sc.nextInt(); nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc int ans = divZero(0, num-1); ans divZero(0, num-1) divZero 0 num-1 num 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args static public int divZero(int start, int end){
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	} divZero {
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	} if(start == end)return nums[end]; start == end start end return nums[end]; nums[end] nums end if(start > end)return 0; start > end start end return 0; 0 for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		} int i = start; int i = start; i start i <= end i end i++ i++ i {
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		} {
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		} if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end); nums[i] == 0 nums[i] nums i 0 return divZero(start, i-1) + divZero(i+1, end); divZero(start, i-1) + divZero(i+1, end) divZero(start, i-1) divZero start i-1 i 1 divZero(i+1, end) divZero i+1 i 1 end int min = 101; min 101 for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i]; int i = start; int i = start; i start i <= end i end i++ i++ i if(nums[i] < min)min = nums[i]; if(nums[i] < min)min = nums[i]; nums[i] < min nums[i] nums i min min = nums[i] min nums[i] nums i for(int i = start; i <= end; i++)nums[i] -= min; int i = start; int i = start; i start i <= end i end i++ i++ i nums[i] -= min; nums[i] -= min nums[i] nums i min return min + divZero(start, end); min + divZero(start, end) min divZero(start, end) divZero start end int start start int end end
import java.util.*;

class Main{
	static int[] nums;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		nums = new int[num];
		for(int i = 0; i < num; i++)nums[i] = sc.nextInt();

		int ans = divZero(0, num-1);
		System.out.println(ans);
	}

	static public int divZero(int start, int end){
		if(start == end)return nums[end];
		if(start > end)return 0;

		for(int i = start; i <= end; i++){
			if(nums[i] == 0)return divZero(start, i-1) + divZero(i+1, end);
		}

		int min = 101;
		for(int i = start; i <= end; i++)if(nums[i] < min)min = nums[i];
		for(int i = start; i <= end; i++)nums[i] -= min;
		return min + divZero(start, end);
	}
}