#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int amar_vote;
  cin >> amar_vote;
  int i = 1;
  priority_queue<int> tini_my_stamina;
  do {
    int x;
    cin >> x;
    tini_my_stamina.push(x);
    i++;
  } while (i < n);
  int vote_suri_koro = amar_vote;
  while (true) {
    int x = tini_my_stamina.top();
    tini_my_stamina.pop();
    if (x < amar_vote) {
      break;
    }
    amar_vote++;
    x--;
    tini_my_stamina.push(x);
  }
  cout << amar_vote - vote_suri_koro << endl;
  return 0;
}
