#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
while (c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-48;c=getchar();}
return x*f;
}
const int MAXN=300005;
int n,k,cnt,ans;
int a[MAXN],b[MAXN],f[MAXN];
int find(int l,int r,int k)
{
int mid;
while (l<r)
{
mid=(l+r)>>1;
if (f[mid]>=k)r=mid;
else l=mid+1;
}
return l;
}
int calc(int n,int c[MAXN])
{
memset(f,0,sizeof(f));
int len=0,k;
for (int i=1;i<=n;i++)
if (c[i]>f[len])f[++len]=c[i];
else f[k=find(1,len,c[i])]=min(f[k],c[i]);
return len;
}
int main()
{
n=read();k=read();
for (int i=1;i<=n;i++) a[i]=read();
cnt=0;
for (int i=1;i<k;i++)
if (a[i]<a[k])b[++cnt]=a[i];
ans+=calc(cnt,b);
cnt=0;
for (int i=k+1;i<=n;i++)
if (a[i]>a[k])b[++cnt]=a[i];
ans+=calc(cnt,b);
printf("%d\n",ans+1);
return 0;
}