import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc ArrayList<Integer> H = new ArrayList<>(); H new ArrayList<>() for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		} int i=0; int i=0; i 0 i<N i N ++i ++i i {
			H.add(sc.nextInt());
		} {
			H.add(sc.nextInt());
		} H.add(sc.nextInt()) H.add H sc.nextInt() sc.nextInt sc sc.close() sc.close sc int c = 0; c 0 int s; s int e; e int min = 101; min 101 for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min); int i = 0; int i = 0; i 0 i < N i N ++i ++i i min = Math.min(H.get(i), min); min = Math.min(H.get(i), min) min Math.min(H.get(i), min) Math.min Math H.get(i) H.get H i min for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min); int i = 0; int i = 0; i 0 i < N i N ++i ++i i H.set(i, H.get(i)-min); H.set(i, H.get(i)-min) H.set H i H.get(i)-min H.get(i) H.get H i min c += min c min while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		} Collections.frequency(H, 0) != H.size() Collections.frequency(H, 0) Collections.frequency Collections H 0 H.size() H.size H {
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		} for (s = 0; H.get(s) == 0; ++s)
				continue; s = 0; s = 0 s 0 H.get(s) == 0 H.get(s) H.get H s 0 ++s ++s s continue; continue; for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue; e = s + 1; e = s + 1 e s + 1 s 1 H.size() > e && H.get(e) != 0 H.size() > e H.size() H.size H e H.get(e) != 0 H.get(e) H.get H e 0 ++e ++e e continue; continue; for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			} int i = s; int i = s; i s i < e i e ++i ++i i {
				H.set(i, H.get(i)-1);
			} {
				H.set(i, H.get(i)-1);
			} H.set(i, H.get(i)-1) H.set H i H.get(i)-1 H.get(i) H.get H i 1 ++c c System.out.println(c) System.out.println System.out System System.out c String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> H = new ArrayList<>();
		for(int i=0;i<N;++i){
			H.add(sc.nextInt());
		}
		sc.close();
		int c = 0;
		int s;
		int e;
		int min = 101;
		for (int i = 0; i < N; ++i)
			min = Math.min(H.get(i), min);
		for (int i = 0; i < N; ++i)
			H.set(i, H.get(i)-min);
		c += min;
		while(Collections.frequency(H, 0) != H.size()){
			for (s = 0; H.get(s) == 0; ++s)
				continue;
			for (e = s + 1; H.size() > e && H.get(e) != 0; ++e)
				continue;
			for (int i = s; i < e; ++i) {
				H.set(i, H.get(i)-1);
			}
			++c;
		}
		System.out.println(c);
	}
}
