#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; queue q; for(int i = 1; i < N - 1; i++) if(A[i - 1] < A[i] && A[i] > A[i + 1]) q.push(i); int ans = 0; while(!q.empty()) { int i = q.front(); q.pop(); A[i] = min(A[i - 1], A[i + 1]) - 1; ans++; if(0 <= i - 2 && A[i - 2] < A[i - 1]) q.push(i - 1); if(i + 2 < N && A[i + 1] > A[i + 2]) q.push(i + 1); } cout << ans << endl; }