"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");

let lines = []

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

reader.on("line", line => {
  lines.push(line);
});

reader.on("close", () => {
  let n = parseInt(lines.shift());
  let h = lines.shift().split(/\s/).map(i => parseInt(i));

  let ans = 0;
  while(h.filter(x => x > 0).length != 0) {
    let l = -1, r = -1;
    
    for (let i = 0; i < n; i++) {
      if (l == -1 && h[i] > 0) l = i;
      if (l != -1 && h[i + 1] <= 0 || i == n - 1) {
        r = i;
        break;
      }
      
    }
    
    for (let i = l; i <= r; i++) {
      h[i] -= 1;
    }
    ans++;
  }
  
  console.log(ans);
});
