#include <iostream>

using namespace std;


signed main()
{
	int n;
	cin >> n;
	int ans = 0;
	int nh = 0;
	for (int i=1; i <= n; i++)
	{
		int a;
		cin >> a;
		if(nh < a)
			ans += a-nh;
		
		nh = a;
	}
	cout << ans << endl;
}
 