#include <bits/stdc++.h>
#define gor(A,B,E) for(int A=B;A<=E;++A)
using namespace std;
inline int read() {
int c,f=1,v=0;while(!isdigit(c=getchar())) if(c=='-')f=-1;
do v*=10,v+=c-'0'; while(isdigit(c=getchar()));return v;
}
const int N = 1e5+3;
int n, a, mn = 0, ans = 0;
int main() {
n = read();
gor(i, 1, n) {
a = read();
if (a - mn > 0) ans += a - mn;
mn = a;
}
cout << ans << endl;
return 0;
}