#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int len, n, i, num, lim, final, temp;
  vector<long long int> arr;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> num;
    if (i == 0) {
      lim = num;
      final = num;
    } else
      arr.push_back(num);
  }
  len = n;
  sort(arr.begin(), arr.end());
  while (arr[len - 2] >= final) {
    arr[len - 2]--;
    final++;
    if (arr[len - 2] < arr[len - 3] && len - 3 >= 0) {
      sort(arr.begin(), arr.end());
    }
  }
  cout << final - lim << endl;
  return 0;
}
