#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long a[n+1];
    long long ans[n+1];
    int i;
    for (i = 1;i <= n;i++) cin >> a[i];
    ans[1] = a[1];
    for (i = 2;i <= n;i++)
    {
        if (a[i] <= a[i-1]) ans[i] = ans[i-1];
        else ans[i] = ans[i-1]+a[i]-a[i-1];
    }
    cout << ans[n];
}
