#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N = 2e5+5;

ll n, a[N], cur = 0, ans = 0;

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