#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int main(void) {
  int n, x, i, num, ans = 0;
  scanf("%d%d", &n, &num);
  for (i = 1; i < n; i++) {
    scanf("%d", &x);
    q.push(x);
  }
  while (1) {
    int a = q.top();
    q.pop();
    if (a >= num) {
      num++;
      a--;
      ans++;
      q.push(a);
    } else
      break;
  }
  cout << ans << "\n";
  return 0;
}
