#include <bits/stdc++.h>
using namespace std;
#define MAXN 100050
int n, a[MAXN];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int prev = 0, ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > prev) ans += a[i] - prev;
prev = a[i];
}
cout << ans << endl;
return 0;
}