#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
pair<int, int> arr[n];
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
arr[i].first = x;
arr[i].second = i;
}
sort(arr, arr + n);
cout << abs(arr[n - 1].second - arr[n - 2].second);
return 0;
}