#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    a.push_back(x);
  }
  int count = 0;
  for (; a[0]++ <= max_element(a.begin() + 1, a.end())[0]--;) count++;
  printf("%d\n", count);
  return 0;
}
