#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
	int ans,t,n,tt;
	cin>>n>>t;
	tt=t;
	ans=t;
	for(int i=2;i<=n;i++){
		cin>>t;
		if(t>tt)ans+=t-tt;
		tt=t;
	}
	printf("%d",ans);
	return 0;
}