var lines = []; var result = 0;

var readline = require("readline");

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function (x) {
  lines.push(x);
});

rl.on('close', function () {
  var N = Number(lines.shift());
  var h = lines.shift().split(" ").map(value => Number(value));


  for (var i = 0; i < 100; i++) {
    var zero = true;

    for (var j = 0; j < N; j++) {

      if (h[j] === 0 && zero === false) { result++; zero = true; }
      if (h[j] === 1) { h[j]--; zero = false; }
      if (1 < h[j]) { h[j]--; zero = false }

    }
    if (0 <= h[N - 1] && zero === false) { result++; }
  }
  console.log(result);
});
