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

int main(void){

    int N; cin>>N;
    int ans=0;
    int tmp; cin>>tmp;
    ans += tmp;
    for (int i = 1; i < N; ++i) {
        int a; cin>>a;
        if(a-tmp > 0) ans+=a-tmp;
        tmp = a;
    }
    cout<<ans<<endl;
    return 0;
}