#include <iostream>
using namespace std;

int main() {
    int n, res = 0;
    cin >> n;
    int h[n+1];
    for(int i = 0; i < n; i++) cin >> h[i+1];
    h[0] = 0;;

    for(int i = 1; i < n+1; i++)    if(h[i-1] < h[i])   res += h[i] - h[i-1];

    cout << res << "\n";
}
