#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int n, temp, bear, point, maxi = 0, counter = 0;
  cin >> n;
  int arra[n];
  for (int i = 0; i < n; i++) {
    cin >> arra[i];
  }
  temp = arra[0];
  sort(arra, arra + n, cmp);
  if (temp == arra[0] && temp > arra[1]) {
    cout << "0";
    return 0;
  } else if (temp == arra[0] && temp == arra[1]) {
    cout << "1";
    return 0;
  }
  while (arra[0] >= temp) {
    temp++;
    arra[0] = arra[0] - 1;
    sort(arra, arra + n, cmp);
    counter++;
  }
  cout << counter;
}
