#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n, x, pre = 0, ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++, pre = x)
        scanf("%d", &x), ans += max(0, x - pre);
    printf("%d", ans);
    return 0;
}