#include<bits/stdc++.h>
#define ll long long
 
using namespace std;
 
int main()
{
    ll i,n;
    cin>>n;
    vector<ll> v(n);
    for(i=0;i<n;i++)
    {
             icn>>v[i]    
    }
    ll cnt = 0;
    for(i=1;i<n;i++)
    {
          if(v[i-1]>v[i])
          {
                    cnt = max (cnt,abs(v[i]-v[i-1])+1);
                     
          }     
    } 
    cout<<cnt<<endl;
    return 0; 
}
