#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> st;
map<int, int>::iterator it;
int main() {
  cin >> n;
  int l;
  cin >> l;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    st[-x]++;
  }
  int ans = 0;
  int flag = -1;
  int mx = -1;
  while (!st.empty()) {
    it = st.begin();
    int val = it->first;
    if (l > -val) {
      flag = -val;
      break;
    }
    int cnt = it->second;
    if (cnt > 0) {
      st[val]--;
      st[val + 1]++;
      ans++;
      l++;
    } else {
      st.erase(it);
    }
  }
  cout << ans << "\n";
  return 0;
}
