#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
template <class T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
inline long long expo(long long base, int nent) {
  if (nent == 1)
    return base;
  else if (nent & 1) {
    long long temp = expo(base, nent / 2);
    temp = (temp * temp) % MOD * base;
    if (temp >= MOD) temp %= MOD;
    return temp;
  } else {
    long long temp = expo(base, nent / 2);
    temp *= temp;
    if (temp >= MOD) temp %= MOD;
    return temp;
  }
}
int main() {
  int arr[105], l, m, c = 1, j, ans = 0, n;
  cin >> n;
  for (int i = 0; i < (int)n; i++) cin >> arr[i];
  l = arr[0];
  sort(arr, arr + n);
  m = arr[n - 1];
  j = n - 2;
  if (l == m && arr[n - 2] != m)
    ;
  else
    while (1) {
      while (arr[j] == m) j--, c++;
      if (c > m - l) {
        ans += (m - l + 1);
        break;
      } else if (c == m - l) {
        ans += c;
        break;
      } else
        ans += c, l += c, m--;
    }
  cout << ans << endl;
  return 0;
}
