import java.util.*;
public class Main {
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	}

	public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	}
} import java.util.*; util.* java public class Main {
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	}

	public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	}
} Main static int count = 0; count 0 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int height[] = new int[num]; height new int[num] num for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < num i num i ++ i ++ i {
			height[i] = sc.nextInt();
		} {
			height[i] = sc.nextInt();
		} height[i] = sc.nextInt() height[i] height i sc.nextInt() sc.nextInt sc reduceHeight(height, 0, num) reduceHeight height 0 num System.out.println(count) System.out.println System.out System System.out count String[] args args public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	} reduceHeight {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	} if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		} first != last first last {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		} int min = height[first]; min height[first] height first int index = first; index first for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			} int i = first; int i = first; i first i < last i last i ++ i ++ i {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			} {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			} if(height[i] < min) {
					min = height[i];
					index = i;
				} height[i] < min height[i] height i min {
					min = height[i];
					index = i;
				} min = height[i] min height[i] height i index = i index i boolean shouldContinue = false; shouldContinue false for(int i = first; i < last; i ++) {
				height[i] -= min;
			} int i = first; int i = first; i first i < last i last i ++ i ++ i {
				height[i] -= min;
			} {
				height[i] -= min;
			} height[i] -= min height[i] height i min count += min count min reduceHeight(height, first, index) reduceHeight height first index reduceHeight(height, index + 1, last) reduceHeight height index + 1 index 1 last int height[] height int first first int last last public class Main {
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	}

	public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	}
} public class Main {
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	}

	public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	}
} Main
import java.util.*;
public class Main {
	static int count = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int height[] = new int[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextInt();
		}

		reduceHeight(height, 0, num);

		System.out.println(count);
	}

	public static void reduceHeight(int height[], int first, int last) {
		if(first != last) {
			int min = height[first];
			int index = first;
			for(int i = first; i < last; i ++) {
				if(height[i] < min) {
					min = height[i];
					index = i;
				}
			}
			boolean shouldContinue = false;
			for(int i = first; i < last; i ++) {
				height[i] -= min;
			}
			count += min;
			reduceHeight(height, first, index);
			reduceHeight(height, index + 1, last);
		}
	}
}