var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
var sizes = input[1].split(' ').map(v => +v);
var count = 0, startIndex, endIndex;
while(true){
    startIndex = sizes.findIndex(v => v > 0);
	if (startIndex < 0) {
      break;
    }
	endIndex = sizes.findIndex((v, index) => v == 0 && index > startIndex)
    if (endIndex < 0) {
      endIndex = sizes.length
    }
	for (;startIndex < endIndex; ++startIndex) {
      --sizes[startIndex];
    }
  	++count;
}
console.log(count);