#include <bits/stdc++.h>
using namespace std;
map<int, int> d;
int main() {
  int n, a, t, org;
  cin >> n >> a;
  org = a;
  for (int i = 0; i < n - 1; ++i) {
    cin >> t;
    ++d[t];
  }
  int x = d.rbegin()->first, y = d.rbegin()->second;
  while (a <= x) {
    if (a + y > x - 1) {
      if (a + y == x)
        a = x;
      else
        a = x + 1;
      break;
    }
    d[x - 1] += y;
    d.erase(x);
    a += y;
    x = d.rbegin()->first, y = d.rbegin()->second;
  }
  cout << a - org << endl;
  return 0;
}
