#include <bits/stdc++.h>

#define int long long
#define pb push_back

using namespace std;


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n, h[200001], ans = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    ans += h[0];
    for(int i = 1; i < n; ++i) {
        if(h[i] > h[i - 1]){
            ans += h[i] - h[i - 1];
        }
    }
    cout << ans;
    return 0;
}
