int main()
{
	int n;
	int amax;
	int C[200000];
	scanf("%d", &n);
	//printf_s("%d\n", n);
	for (int t = 0; t < n; t++)
	{
     scanf("%d", &C[t]);
    }

	amax = C[1] - C[0];
	for (int j = 1; j < n; j++)
	{
		for (int t = j + 1; t < n; t++)
		{

			if (C[t]>=C[j]&& C[t-1]>=C[t])
			{
			int comp = C[t] - C[j];
			if (amax < comp)
			{
				amax = comp;
			}
			}
		}
	}
	
	printf("%d\n", amax);
	return 0;
}