#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define dbg(x) cerr << x << endl

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll N;
	cin >> N;

	ll result, prev, temp;
	cin >> prev;
	result = prev;

	for (size_t i = 1; i < N; i++)
	{
		cin >> temp;
		if (temp > prev)
		{
			result += (temp - prev);
		}
		prev = temp;
	}

	dbg("Result = " << result);

	cout << result << endl;
	return 0;
}