"use strict";
const lines = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n");
const hs = lines[1].split(" ");
let h = [];
for(let i = 0; i < hs.length; i++){
  h.push(parseInt(hs[i]));
}

const n = h.length;
let i;
for(let j = 0; ; j++){
  for(i = 0; h[i] === 0 && i < n; i++){}
  if(i === n){
    console.log(j);
    break;
  }
  for(; i < n; i++){
    if(h[i] > 0){
      h[i]--;
    }else{
      break;
    }
  }
}


