#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, x, maxx, c = 0;
  scanf("%d", &n);
  n--;
  vector<int> arr(n);
  scanf("%d", &x);
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  for (i = 0;; i++) {
    maxx = max_element(arr.begin(), arr.end()) - arr.begin();
    if (x > arr[maxx]) {
      printf("%d", c);
      break;
    } else {
      x++;
      arr[maxx]--;
      c++;
    }
  }
}
