import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array, std.functional;

void main() {
  auto N = readln.split[0].to!int;
  auto h = readln.split.to!(int[]);

  h ~= 0;

  auto res = 0;
  while(h.reduce!max > 0) {
    foreach(i; 0..N) {
      if(h[i] > 0) {
        h[i]--;
        if(h[i+1] == 0) res++;
      }
    }
  }
  res.writeln;
}
