#include <bits/stdc++.h>
using namespace std;
int main() {
  multiset<int> c;
  int n;
  cin >> n;
  int a;
  cin >> a;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    c.insert(a);
  }
  int cnt = 0;
  while (a <= *prev(c.end())) {
    ++cnt;
    ++a;
    int t = *prev(c.end());
    c.erase(prev(c.end()));
    c.insert(--t);
  }
  cout << cnt << endl;
  return 0;
}
