#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Limak, Limak0, dif;
  cin >> N;
  int votes;
  vector<int> v;
  for (int i = 0; i < N; i++) {
    cin >> votes;
    v.push_back(votes);
  }
  Limak = v[0];
  Limak0 = Limak;
  v[0] = -1;
  for (int i = 0;; i++) {
    sort(v.begin(), v.end());
    if (Limak > v[N - 1]) {
      if (i == 0) {
        cout << "0\n";
        return 0;
      } else {
        cout << Limak - Limak0 << "\n";
        return 0;
      }
    } else {
      Limak++;
      v[N - 1]--;
    }
  }
}
