#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	LL sum = 0;
	int l = 0;
	int n;
	int N;
	scanf("%d",&N);
	while(N --){
		int x;
		scanf("%d",&x);
		int buf = x - l;
		l = x;
		if(buf > 0) sum += buf;
	}
	cout<<sum<<endl;
	return 0;
}