#include <bits/stdc++.h>
using namespace std;

int p[200000];
int main(){
int n, k;cin>>n>>k;for(int i=0;i<n;i++)cin>>p[i];
int pos1=-1;
for(int i=0;i<n;i++)if(p[i]==1)pos1=i;
cout<<min(i+1-k+1, n-i-k+1);
}