function main(input) {
  var n = input[0]-0;
  var h = input[1].split(" ").map(v=>v-0);
  var ans = 0;
  var start, end;
  for(start=0;start<n;){
    if(h[start]==0) {start++; continue;}
    var min = h[start];
    for(end=start;end<n;end++){
      if(h[end] == 0) break;
      min = Math.min(h[end], min);
    }
    for(var i=start;i<end;i++){
      h[i]-=min;
    }
    ans += min;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))
