#include <bits/stdc++.h>
int findmax(int *a, int n) {
  int max = -99999, i, g;
  for (i = 1; i <= n; i++)
    if (a[i] > max) {
      max = a[i];
      g = i;
    }
  return g;
}
int main() {
  int n, a[1007], i, g, k, p;
  scanf("%d", &n);
  a[0] = 0;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  p = findmax(a, n);
  g = a[1];
  int fl = 1;
  while (1) {
    if (a[p] == a[1]) {
      for (i = 2; i <= n; i++)
        if (a[i] == a[1]) {
          a[1] = a[1] + 1;
          a[i] = a[i] - 1;
          fl = 0;
          break;
        }
      break;
    } else {
      a[p] = a[p] - 1;
      a[1] = a[1] + 1;
      k = a[1];
      p = findmax(a, n);
    }
  }
  printf("%d\n", a[1] - g);
  return 0;
}
