import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	static int cnt;
	void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	}

	void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} import java.util.*; util.* java public class Main {
	Scanner sc = new Scanner(System.in);

	static int cnt;
	void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	}

	void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static int cnt; cnt void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	} doIt {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n int min = 101; min 101 cnt = 0 cnt 0 for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		} {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc if(h[i] < min)min = h[i]; h[i] < min h[i] h i min min = h[i] min h[i] h i getAns(h, 0, n - 1, 0) getAns h 0 n - 1 n 1 0 System.out.println(cnt) System.out.println System.out System System.out cnt void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	} getAns {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	} if(l > r)return; l > r l r return; int min = 101 min 101 idx = -1; idx -1 1 for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		} int i = l; int i = l; i l i <= r i r i++ i++ i {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		} {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		} if(min > h[i]) {
				min = h[i];
				idx = i;
			} min > h[i] min h[i] h i {
				min = h[i];
				idx = i;
			} min = h[i] min h[i] h i idx = i idx i cnt += min - d cnt min - d min d if(min <= d)min = d; min <= d min d min = d min d if(min - d == 0) d = 0; min - d == 0 min - d min d 0 d = 0 d 0 getAns(h, l, idx - 1, min) getAns h l idx - 1 idx 1 min getAns(h, idx + 1, r, min) getAns h idx + 1 idx 1 r min int[] h h int l l int r r int d d public static void main(String[] args) {
		new Main().doIt();
	} main {
		new Main().doIt();
	} new Main().doIt() new Main().doIt new Main() String[] args args public class Main {
	Scanner sc = new Scanner(System.in);

	static int cnt;
	void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	}

	void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} public class Main {
	Scanner sc = new Scanner(System.in);

	static int cnt;
	void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	}

	void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} Main
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	static int cnt;
	void doIt() {
		int n = sc.nextInt();
		int[] h = new int[n];
		int min = 101;
		cnt = 0;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			if(h[i] < min)min = h[i];
		}
		getAns(h, 0, n - 1, 0);
		System.out.println(cnt);
	}

	void getAns(int[] h, int l, int r, int d) {
		if(l > r)return;
		int min = 101, idx = -1;
		for(int i = l; i <= r; i++) {
			if(min > h[i]) {
				min = h[i];
				idx = i;
			}
		}
		cnt += min - d;
		if(min <= d)min = d;
		if(min - d == 0) d = 0;
		getAns(h, l, idx - 1, min);
		getAns(h, idx + 1, r, min);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}
