#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  priority_queue<int> Q;
  cin >> n;
  cin >> m;
  for (int i = 1; i < n; i++) {
    cin >> x;
    Q.push(x);
  }
  int ans = 0;
  while (!Q.empty()) {
    x = Q.top();
    Q.pop();
    if (m > x) {
      break;
    }
    ans++;
    m++;
    x--;
    Q.push(x);
  }
  cout << ans << endl;
}
