#include <bits/stdc++.h>
int main() {
  long long int n, a[20000], i, j, temp, f = 0;
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (i = n; i >= 3; i--) {
    for (j = n; j >= 3; j--) {
      if (a[j] > a[j - 1]) {
        temp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = temp;
      }
    }
  }
  for (;;) {
    if (a[1] > a[2]) break;
    f++;
    a[1] = a[1] + 1;
    a[2] = a[2] - 1;
    for (i = n; i >= 3; i--) {
      if (a[2] + 1 == a[i]) {
        temp = a[2];
        a[2] = a[i];
        a[i] = temp;
        break;
      }
    }
  }
  printf("%I64d", f);
}
