import std.array;
import std.conv;
import std.string;
import std.algorithm;
import std.stdio;

void main() {
	int n = readln.chomp.to!int;
	auto a = readln.chomp.split(' ').map!(to!int).array;
	auto m = reduce!max(a);
	int count;
	bool top = false;

	while (m > 0) {
		foreach (ref e;a) {
			if (top) {
				if (e == m) {
					--e;
				} else {
					top = false;
				}
			} else {
				if (e == m) {
					top = true;
					++count;
					--e;
				}
			}
		}

		top = false;
		--m;
	}

	count.writeln;
}
