#include<iostream>
using namespace std;
const int N=100010;
int a;
int mc[N];
int main()
{
cin>>a;
for(int i=1;i<=a;i++)
cin>>mc[i];
for(int i=a+1;i>=0;i--)
mc[i]-=mc[i-1];
int ans=0;
for(int i=1;i<=a+1;i++)
{
if(mc[i]>=0)
ans+=mc[i];
}
cout<<ans<<endl;
return 0;
}