#include <bits/stdc++.h>   using namespace std;   int main() {     int n, lam, mx = 0, c = 0;     cin >> n;     vector<int> cand(n);     for (int i = 0; i < n; i++) {       cin >> cand[i];       if (mx < cand[i]) mx = cand[i];     }     for (int i = 0; i < n; i++)       if (mx == cand[i]) c++;     int x = lam = cand[0];     if (lam == mx && c > 1) return cout <<  1 , 0;     if (lam == mx && c == 1) return cout <<  0 , 0;     sort(cand.begin(), cand.end());     while (lam <= cand[n - 1]) {       lam += 1;       cand[n - 1] -= 1;       sort(cand.begin(), cand.end());     }     cout << lam - x;   }   