#include<cstdio>
long long a[100005],n,s;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	    scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++)
	    if (a[i]>a[i-1]) s=s+a[i]-a[i-1];
	printf("%lld\n",s);
    return 0;
} 