#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int gizzly;
  cin >> gizzly;
  priority_queue<int> scoreList;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    scoreList.push(x);
  }
  int candy = 0;
  while (gizzly <= scoreList.top()) {
    int opponent = scoreList.top();
    scoreList.pop();
    opponent -= 1;
    gizzly += 1;
    candy += 1;
    scoreList.push(opponent);
  }
  cout << candy << endl;
  return 0;
}
