#include <bits/stdc++.h>
using namespace std;
bool descendente(int i, int j) { return i > j; }
int restarDos(int iA, int iB, vector<vector<int> > &iMemory) {
  if (iA <= iB) {
    if (iMemory[iA][iB] > -1) {
      return iMemory[iA][iB];
    } else if (iMemory[iA][iB] == -1) {
      iMemory[iA][iB] = restarDos(iA + 1, iB - 1, iMemory);
      return iMemory[iA][iB];
    }
  } else {
    return iA;
  }
}
void generalizarDiff(int iDiff, std::vector<int> &iNums) {
  while (iDiff != 0) {
    --iNums[0];
    --iDiff;
    if (iNums[0] < iNums[1]) sort(iNums.begin(), iNums.end(), descendente);
  }
}
int main() {
  bool sync_with_stdio(bool sync = false);
  vector<vector<int> > iMemory(2010, vector<int>(2010, -1));
  int iN, iTemp, iBear, iTot = 0, iDiff;
  bool esMenor = true;
  cin >> iN >> iBear;
  std::vector<int> iNums;
  if (iN >= 2) {
    for (int i = iN - 1; i != 0; --i) {
      cin >> iTemp;
      iNums.push_back(iTemp);
    }
    sort(iNums.begin(), iNums.end(), descendente);
    while (esMenor) {
      if (iBear <= iNums.front()) {
        iTemp = restarDos(iBear, iNums.front(), iMemory);
        iDiff = iTemp - iBear;
        iTot += iDiff;
        generalizarDiff(iDiff, iNums);
        iBear = iTemp;
        sort(iNums.begin(), iNums.end(), descendente);
      } else {
        esMenor = false;
      }
    }
  }
  cout << iTot << '\n';
  return 0;
}
