console.log((args=>{
  const [[N],h] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  let o = h[0];
  for ( let i = 1; i < N; i++ ) {
    if ( h[i] > h[i-1] ) o += h[i] - h[i-1];
  }
  return `${o}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
