#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> big;
  int n, num, i, j, cnt = 0;
  scanf("%d", &n);
  scanf("%d", &num);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d", &j);
    if (j >= num) big.push_back(j);
  }
  int siz = big.size();
  if (siz == 0) {
    printf("0\n");
    return 0;
  }
  sort(big.rbegin(), big.rend());
  int pos = 0;
  j = big[0];
  while (pos < siz && num <= j) {
    while (pos < siz && big[pos + 1] == j) pos++;
    if (j - num <= pos) {
      cnt += j - num + 1;
      num += j - num + 1;
      break;
    }
    cnt += pos + 1;
    num += pos + 1;
    j--;
  }
  printf("%d\n", cnt);
  return 0;
}
