#include<bits/stdc++.h>
using namespace std;

int main() {
	int n,cnt{},prev{};
	cin >> n;
	for(int i=0; i<n; i++){
		int h;
		cin >> h;
		if(prev<h) cnt += h-prev;
		prev = h;
	}
	cout << cnt << endl;
}