#include<cstdio>
#define Rint register int
using namespace std;
const int N = 100003;
int n, d[N], ans;
int main(){
scanf("%d", &n);
for(Rint i = 1;i <= n;i ++){
scanf("%d", d + i);
if(d[i] > d[i - 1]) ans += d[i] - d[i - 1];
}
printf("%d\n", ans);
}