function Main(input){
    // 入力値取得
    input = input.split("\n");
    tmp = input[1].split(" ");
    var people = input[0];
    var diff = 0;
    var dai = 0;

    // tmpの数字をループして
    for (var i = 0; i <= people; i++) {
      if((tmp[i+1] - tmp[i]) > 0) {
        diff = tmp[i+1] - tmp[i]
        dai = dai + Math.abs(diff)
      } else {
        dai = dai
      }
    }
    console.log(dai);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));