#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int v;
  cin >> v;
  vector<int> a(n - 1);
  for (int &i : a) cin >> i;
  sort(a.begin(), a.end());
  int ans = v;
  reverse(a.begin(), a.end());
  while (a[0] >= ans) {
    ans++;
    a[0]--;
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
  }
  cout << ans - v << '\n';
  exit(0);
}
