#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
  int N;
  int cnt = 0, C = 0;
  cin >> N;
  int h[N];
  for(int i = 0;i < N; ++i){
    cin >> h[i];
    if(h[i] > C)
      cnt += h[i] - C;
    C = h[i];
  }
  
  cout << cnt << endl;
}  