#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long MOD = 1000000007;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int a, tmp, ans = 0;
    scanf("%d", &a);
    priority_queue<int> pq;
    for (int i = 1; i < n; i++) {
      scanf("%d", &tmp);
      if (tmp >= a) pq.push(tmp);
    }
    while (!pq.empty() && a <= pq.top()) {
      int maxv = pq.top();
      pq.pop();
      ans++;
      a++;
      maxv--;
      pq.push(maxv);
    }
    printf("%d\n", ans);
  }
  return 0;
}
