# include "iostream"
# include "cstdio"

using namespace std;

const int maxm=1e5+10;

int N,A[maxm];

int main(){
	register int i,Ans=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++) scanf("%d",A+i);
	for(i=1;i<=N;i++){
		if(A[i]<A[i-1]) continue;
		Ans+=(A[i]-A[i-1]);
	}
	printf("%d",Ans);
	return 0;
}