#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    int S = h[N-1];
    for(int i = 1; i < N; i++){
        if(h[i-1] > h[i]) S += h[i-1] - h[i];
    }
    cout << S << endl;
}
