#include <bits/stdc++.h>
using namespace std;
int a[1000100], b[5010];
string second[10];
int main() {
  int n, sm = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n);
  for (;;) {
    if (a[0] <= a[n - 1]) {
      a[n - 1]--;
      a[0]++;
      sm++;
    }
    sort(a + 1, a + n);
    if (a[0] > a[n - 1]) {
      cout << sm;
      return 0;
    }
  }
  return 0;
}
