process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ！！

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
 
  var N = parseInt(lines[0],10);
  var need = lines[1].split(' ').map(value=>parseInt(value,10));
  var print = (value)=>console.log(value);

  var count = 0;
  
  for(var i=0;i<N;i++){
  	while(need[i] !==0){
      need[i] --;
      for(var j=i+1;j<N;j++){
      	if(need[j] !==0){
        	need[j]--;
        }else{
        	break;
        }
      }
      
      count++;
    }
    
  
  }
  print(count);
  
});