#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int solve(void) {
  priority_queue<int> pq;
  int now, ans = 0;
  scanf("%d", &now);
  for (int i = 0; i < n - 1; i++) {
    int ai;
    scanf("%d", &ai);
    pq.push(ai);
  }
  int tmp;
  while ((tmp = pq.top()) >= now) {
    pq.pop();
    pq.push(--tmp);
    now++;
    ans++;
  }
  return ans;
}
int main(void) {
  while (~scanf("%d", &n)) printf("%d\n", solve());
  return 0;
}
