#include <iostream>
using namespace std;
int ans;
int main()
{
int n;
scanf("%d",&n);
int a[n+1];
a[0] = 0;
int Min = 1e9+7;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
if(a[i]-a[i-1] > 0)
ans += a[i]-a[i-1];
}
cout<<ans;
return 0;
}