#include <bits/stdc++.h>
using namespace std;
int arr[100];
int main() {
  int n, p;
  scanf("%d", &n);
  int limak;
  scanf("%d", &limak);
  priority_queue<int> pq;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &p);
    pq.push(p);
  }
  int count = 0;
  if (limak > pq.top()) {
    printf("0\n");
  } else {
    int count = 0;
    while (true) {
      int u = pq.top();
      pq.pop();
      if (limak == u) {
        limak++;
        count++;
        u--;
      }
      if (limak > u) break;
      while (true) {
        limak++;
        count++;
        u -= 1;
        pq.push(u);
        u = pq.top();
        if (u <= limak) break;
        pq.pop();
      }
    }
    printf("%d\n", count);
  }
  return 0;
}
