#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y = 0;
  cin >> n;
  int N[n];
  cin >> x;
  for (int i = 0; i < n - 1; i++) cin >> N[i];
  sort(N, N + n - 1);
  if (x <= N[n - 2]) {
    while (x <= N[n - 2]) {
      x += 1;
      y += 1;
      N[n - 2] -= 1;
      sort(N, N + n - 1);
    }
    cout << y;
  } else
    cout << 0;
}
