#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d;
for (int i = 1; i <= n; ++i) {
cin >> d[i];
}
int days = 0;
while (true) {
int maxD = -1, maxI = -1;
for (int i = 0; i < n; ++i) {
if (d[i] > maxD && d[i] != 0) {
maxD = d[i];
maxI = i;
}
}
if (maxDepth == -1) break;
int left = maxI, right = maxI;
while (left >= 0 && d[left] != 0) --left;
while (right < n && d[right] != 0) ++right;
for (int i = left + 1; i < right; ++i) {
d[i]--;
}
days++;
}
cout << days << endl;
return 0;
}