#include <bits/stdc++.h>

#define MAX_N 1000006

int64_t n;
std::pair<int64_t, int64_t> arr[MAX_N];

int len(int64_t a, int64_t b) {
	if (a > b) return a - b + 1;
	else       return b - a + 1;
}

int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);
	
	std::cin >> n;
	for (int64_t i = 0; i < n; i += 1) {
		std::cin >> arr[i].first;
		arr[i].second = i;
	}
	
	std::sort(arr, arr + n, std::greater<std::pair<int64_t, int64_t> >());
		
	int64_t ans = -n;
	for (int64_t i = 1; i < n; i +=1) {
		for (int64_t j = 0; j < i; j += 1) {
			ans = std::max(ans, arr[i].first - len(arr[i].second, arr[j].second));
		}
	}
	
	std::cout << ans << std::endl;
}
/*
5
3 1 4 1 59
*/