#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int main() {
  int n, temp, i, tar, temp2, ans = 0;
  scanf("%d", &n);
  scanf("%d", &tar);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &temp);
    q.push(temp);
  }
  while (!q.empty() && tar <= q.top()) {
    temp = q.top();
    q.pop();
    ans++;
    tar++;
    temp--;
    if (temp >= tar) q.push(temp);
  }
  printf("%d\n", ans);
  return 0;
}
