#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  priority_queue<int> q;
  int my;
  cin >> my;
  int x;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    q.push(x);
  }
  int steps = 0;
  while (true) {
    if (my <= q.top()) {
      q.push(q.top() - 1);
      q.pop();
      my++;
      steps++;
    } else
      break;
  }
  cout << steps << endl;
  return 0;
}
