#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, k = 0, orig, arr[1010], i;
  memset(arr, 0, sizeof(arr));
  cin >> n;
  cin >> k;
  for (i = 0; i < n - 1; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n - 1);
  int ans = 0;
  while (k <= arr[n - 2]) {
    k++;
    arr[n - 2]--;
    ans++;
    if (arr[n - 2] < arr[n - 3]) {
      sort(arr, arr + n - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
