#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q;
int n, m, k;
int main() {
  for (cin >> m >> m; cin >> n;) q.push(n);
  for (; m <= q.top(); m++, k++) n = q.top(), q.pop(), q.push(--n);
  cout << k;
}
