#include<bits/stdc++.h>
using namespace std;
int n,h[200],ans=0;
signed main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    h[n]=0;
    for(int i=0;i<n;i++){
        ans+=max(0,h[i]-h[i+1]);
    }
    cout<<ans<<endl;
    return 0;
} 