#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
int max1 , max2;
int index1 = 0;
max1 = arr[index1];
for (int j = 0; j < n; ++j)
{
if (max1 < arr[j])
{
max1 = arr[j];
index1 = j;
}
}
int index2 = index1 + 1;
max2 = arr[index2];
for (int i = 0; i < n; ++i)
{
if (max2 < arr[i] && arr[i] < max1)
{
max2 = arr[i];
index2 = i;
}
}
int space;
if (index1 > index2)
{
space = index1 - index2;
}
else
{
space = index2 - index1;
}
cout << space;
return 0;
}