#include <bits/stdc++.h>
#define LOCAL
#define ll long long
#define lll unsigned long long
#define MAX 1000009
#define mod 1000000007
using namespace std;
/*
题意:
想法:
*/
vector<int>a;
bool cmp(int x,int y)
{
return x > y;
}
int main()
{
//freopen("date.txt","r",stdin);
int n,m;
int ans,x;
cin>>n;
cin>>m;
ans = m;
for(int i = 0; i<n - 1; i++)
{
scanf("%d",&x);
a.push_back(x);
}
sort(a.begin(),a.end(),cmp);
while(1)
{
//cout<<a[0]<<endl;
if(m<=a[0])//每次排序与数组最大值比较,如果小于等于本身自增,最大值自减
{
a[0]--;
m++;
sort(a.begin(),a.end(),cmp);
}
else
{
break;
}
}
cout<<m - ans<<endl;
return 0;
}