#include <stdio.h>
using namespace std;
int main()
{
    int n, s, max1, t, max2;
    scanf("%d", &n);
    int Arr[n];
    for(int i=0; i<n; i++)
    {
        scanf("%d", &Arr[i]);
    }
    if(Arr[0]>Arr[1]) s = Arr[1] - 1;
    else s = Arr[0] - 1;
    for(int i=2; i<n+1; i++)
    {
        for(int j=i; j<n-i; j++)
        {
            max1=Arr[j];
            for(int k=j; k<i+j; k++)
            {
                if(max1<Arr[k])
                {
                    max1 = Arr[k];
                    t = k;
                }
            }
            Arr[t] = Arr[j];
            Arr[j] = max1;
            max2 = Arr[j+1];
            for(int k=j+1; k<i+j; k++)
            {
                if(max2<Arr[k]) max2 = Arr[k];
            }
            Arr[j] = Arr[t];
            Arr[t] =max1;
            if(s< max2 - i) s = max2 - i;
        }
    }
    printf("%d", (s+1));
}
