#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  priority_queue<int> pq;
  int base;
  cin >> base;
  for (int i = 1; i < n; i++) {
    int a;
    cin >> a;
    if (a >= base) pq.push(a);
  }
  int cnt = 0;
  while (pq.empty() == false && pq.top() >= base) {
    int t = pq.top();
    pq.pop();
    pq.push(t - 1);
    base++;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
