import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		h = new int[N];
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]);

	}

	int[] h;

	public void solve() {
		int ans = 0;
		for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		}

		System.out.println(ans);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		} ; solver.hasNext() solver.hasNext solver {
			solver.readBody(in.readLine());
		} {
			solver.readBody(in.readLine());
		} solver.readBody(in.readLine()) solver.readBody solver in.readLine() in.readLine in solver.solve() solver.solve solver String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		h = new int[N];
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]);

	}

	int[] h;

	public void solve() {
		int ans = 0;
		for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		}

		System.out.println(ans);
	}
} Solver int N; N int cnt; cnt int[] h; h public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		h = new int[N];
	} readHead {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		h = new int[N];
	} String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " N = Integer.parseInt(strArr[0]) N Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 h = new int[N] h new int[N] N String str str public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	} hasNext {
		// return cnt < N;
		return cnt < 1;
	} return cnt < 1; cnt < 1 cnt 1 public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]);

	} readBody {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]);

	} cnt++ cnt String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]); int i = 0; int i = 0; i 0 i < N i N i++ i++ i h[i] = Integer.parseInt(strArr[i]); h[i] = Integer.parseInt(strArr[i]) h[i] h i Integer.parseInt(strArr[i]) Integer.parseInt Integer strArr[i] strArr i String str str public void solve() {
		int ans = 0;
		for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		}

		System.out.println(ans);
	} solve {
		int ans = 0;
		for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		}

		System.out.println(ans);
	} int ans = 0; ans 0 for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		} ; {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		} {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		} int l = 0; l 0 for (; l < N && h[l] <= 0; l++) {
			} ; l < N && h[l] <= 0 l < N l N h[l] <= 0 h[l] h l 0 l++ l++ l {
			} {
			} if (l >= N)
				break; l >= N l N break; ans++ ans for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			} int r = l; int r = l; r l r < N r N r++ r++ r {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			} {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			} if (h[r] > 0)
					h[r]--;
				else
					break; h[r] > 0 h[r] h r 0 h[r]-- h[r] h r break; System.out.println(ans) System.out.println System.out System System.out ans
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		h = new int[N];
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		for (int i = 0; i < N; i++)
			h[i] = Integer.parseInt(strArr[i]);

	}

	int[] h;

	public void solve() {
		int ans = 0;
		for (;;) {
			// for (int i = 0; i < N; i++)
			// System.out.print(" " + h[i]);
			// System.out.println();

			int l = 0;
			for (; l < N && h[l] <= 0; l++) {
			}
			if (l >= N)
				break;

			ans++;
			for (int r = l; r < N; r++) {
				if (h[r] > 0)
					h[r]--;
				else
					break;
			}

		}

		System.out.println(ans);
	}
}
