#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,h,hp=0,ans=0;
    cin >> N;
    for (int i=0;i<N;i++) {
        cin >> h;
        if (h>hp) ans += h - hp;
        hp = h;
    }
    cout << ans << '\n';
    return 0;
}