#include <bits/stdc++.h>
using namespace std;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int* arr;
    arr = new int[n];
    int ans = 0;
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    bool type = false;
    int m = arr[0];
    for (int i = 0; i < n; ++i){
        if (arr[i] > m)
            m = arr[i];
    }
    while (m >= 0){
        type = false;
        for (int i = 0; i < n; ++i){
            if (arr[i] == 0)
                type = false;
            else{
                if(type == true){
                    arr[i]--;
                }
                else{
                    ans++;
                    type = true;
                    arr[i]--;
                }
            }
        }
        m--;
    }
    cout << ans;
    return 0;
}
