#include <iostream>

using namespace std;

int N;
int h[100];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> h[i];
    int c = h[0];
    for(int i=1;i<N;i++){
        if(h[i-1] < h[i]) c += (h[i]-h[i-1]);
    }
    cout << c << endl;
    return 0;
}