#include<bits/stdc++.h>
using namespace std;
long long checker[100001];
int main()
{
    long long n;
    cin>>n;
    long long a, prev, currMin = -1;
    long long res = 100001, br = 0, c = 0;
    for(int i = 0; i < n; i++)
    {

        cin>>a;
        if(c == 1) continue;
        if(a == 0) c = 1;
        if(i == 0)
        {
            prev = a;
            continue;
        }
        if(a > prev) checker[i]++;
        if(prev > a) checker[i-1]++;
        if(checker[i-1] == 2)
        {
            if(currMin != -1)res = min(res, (i-1)-currMin-1);
            ///cout<<"res:"<<res<<endl;
            br++;
            currMin = i-1;
        }
        ///cout<<i-1<<" "<<checker[i-1]<<endl;
        prev = a;
    }
    if(br == 1 || br == 0) res = 0;
    cout<<res;

    return 0;
}
