#include <bits/stdc++.h>   using namespace std;   int *s;   int fenzhi(int left, int right, int d) {     int mins = 0x3f3f3f3f;     ;     for (int i = left; i <= right; i++) mins = min(mins, s[i] - d);     int ans = 0;     for (int i = left; i <= right; i++)       if (s[i] > mins + d) {         int j = i;         while (s[j + 1] > mins + d && j + 1 <= right) j++;         ans += fenzhi(i, j, mins + d);         i = j + 1;       }     return min(right - left + 1, mins + ans);   }   int main() {     int n;     cin >> n;     s = new int[n];     for (int i = 0; i < n; i++) cin >> s[i];     cout << fenzhi(0, n - 1, 0) << endl;     delete[] s;     return 0;   }   