#include <bits/stdc++.h>

using namespace std;

typedef pair<long,long> pll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair

vector <long> v;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long n;
    cin >> n;
    v.resize(n);
    for (long i = 0;i < n;i++) cin >> v[i];
    long long ans = 0;
    for (long i = 1;i < n;i++)
        if (v[i] < v[i-1]) ans += v[i-1]-v[i];
    cout << ans + v[n-1] << '\n';
    return 0;
}
