#include <bits/stdc++.h>
using namespace std;
int lim;
priority_queue<int> q;
void parse() {
  int n;
  cin >> n;
  cin >> lim;
  int tmp;
  for (int i = 1; i < n; i++) {
    cin >> tmp;
    if (tmp >= lim) q.push(tmp);
  }
}
void solve() {
  int r = 0;
  while (!q.empty()) {
    int t = q.top();
    q.pop();
    if (t >= lim) {
      r++;
      lim++;
      t--;
      q.push(t);
    }
  }
  cout << r;
}
int main() {
  ios::sync_with_stdio(false);
  std::cout.precision(11);
  parse();
  solve();
  cout << endl;
  return 0;
}
