#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
priority_queue<int> q;
int main() {
  int n, a, x;
  scanf("%d", &n);
  scanf("%d", &a);
  for (int i = 1; i < n; i++) {
    scanf("%d", &x);
    q.push(x);
  }
  if (q.empty()) {
    printf("0\n");
    return 0;
  }
  int ans = 0;
  int t = q.top();
  q.pop();
  while (a <= t) {
    ans++;
    a++;
    t--;
    q.push(t);
    t = q.top();
    q.pop();
  }
  printf("%d\n", ans);
  return 0;
}
