#include <bits/stdc++.h>
using namespace std;
int n, ss[10005], a, b;
int main() {
  int mx = 0;
  memset(ss, 0, sizeof(ss));
  scanf("%d", &n);
  scanf("%d", &a);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &b);
    ss[b]++;
    mx = max(mx, b);
  }
  if (a > mx) {
    printf("0\n");
  } else {
    int i = mx;
    b = a;
    for (; i >= 1; i--) {
      if (ss[i] != 0) {
        while (ss[i]--) {
          if (a > i) {
            break;
          }
          a++;
          ss[i - 1]++;
        }
        if (a > i) {
          break;
        }
      }
    }
    printf("%d\n", a - b);
  }
  return 0;
}
