#include<iostream>
using namespace std;
int main()
{
    int n, hbef = 0, haft, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        scanf("%d", &haft);
        if(haft >= hbef) ans += haft - hbef;
        hbef = haft;
    }
    cout << ans << endl;
    return 0;
}