#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  priority_queue<long long> pq;
  long long ans;
  cin >> ans;
  for (long long i = 1; i < n; i++) {
    cin >> a[i];
    pq.push(a[i]);
  }
  long long cnt = 0;
  while (!pq.empty()) {
    long long x = pq.top();
    if (ans + cnt <= x) {
      cnt++;
      pq.pop();
      pq.push(x - 1);
    } else
      break;
  }
  cout << cnt << '\n';
}
