#include <bits/stdc++.h>
using namespace std;
int main() {
  short n, *a, record = 0;
  int c = 0;
  cin >> n;
  a = new short int[n];
  for (short i = 0; i < n; i++) cin >> a[i];
  sort(a + 1, a + n);
  short i;
  for (i = 1; i < n && a[0] > a[i]; i++)
    ;
  record = i;
  while (record < n) {
    sort(a + record, a + n);
    {
      if (a[n - 1] >= a[0]) {
        c++;
        a[0]++;
        a[n - 1]--;
      }
    }
    for (; a[0] > a[record]; record++)
      ;
  }
  printf("%d\n", c);
  delete[] a;
  return 0;
}
