#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n;
int res;
int d[N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d", &d[i]);//如果a[i]>a[i-1],则a[i-1]可以在填a[i]时填完, 否则则相反
if(d[i]>d[i-1]) res+=d[i]-d[i-1];
}
cout<<res<<endl;
return 0;
}