#include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
int ans=0,active=0;
cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++)cin >> a[i];

for(int i=0;i<n;i++){
if(active >= a[i]){
active = a[i];
}else{
ans += a[i] - active;
active = a[i];
}
}
cout << ans << endl;
return 0;
}