#include<iostream>
int main(){
  int n, h, prev = 0, ans = 0;
  std::cin >> n;
  while(n--){
    std::cin >> h;
    if(prev < h)
        ans += h - prev;
    prev = h;
  }
  std::cout << ans << std::endl;
  return 0;
}
