#include <iostream>
using namespace std;
int main()
{
int n , x , big , Big , no1 , no2;
cin >> n;
big = 0;
Big = 0;
no1 = 0;
no2 = 0;
for ( int i = 0 ; i < n ; i ++ )
{
cin >> x;
if ( x > Big )
{
big = Big;
no1 = no2;
Big = x;
no2 = i;
}
else if ( x > big )
{
big = x;
no1 = i;
}
}
cout << abs(no2 - no1);
return 0;
}