#include <bits/stdc++.h>
using namespace std;

int CountHeight(vector<int>& heights) {
  int sum = 0;
  for (int i = 1; i < heights.size(); ++i) {
    if (heights[i] <= heights[i-1]) {
      sum += (heights[i-1] - heights[i]) + 1;
    }
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  vector<int> arr;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    arr.push_back(x);
  }
  