### BUGGY CODE ###

def main():

    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    
    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m
    
    for i in range(262143,m):
        segtree[i]=x[i-262143]
    	
    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=-1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=min(segtree[2*i+1],segtree[2*i+2])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,0)]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,l+1))
                qq.append((ii,jj,2*now+2,l+1))
        min_list.append(min(s))
       
    for i in range(262142,-1,-1):
        if 2*i+1>=m:
            segtree[i]=n+1
        elif 2*i+2>=m:
            segtree[i]=segtree[2*i+1]
        else:
            segtree[i]=max(segtree[2*i+1],segtree[2*i+2])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,0)]
        s=set()
        while qq:
            ii,jj,now,l=qq.pop()
            kubun=2**l
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,l+1))
                qq.append((ii,jj,2*now+2,l+1))
        max_list.append(max(s))
        
    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False
    
    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False
            
    print(sum(flag))

if __name__ == '__main__':
	main()


### FIXED CODE ###

def main():
    import sys
    input=sys.stdin.readline
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    
    min_list=[]
    max_list=[]
    m=262143+n
    segtree=[-1]*m
    
    for i in range(262143,m):
        segtree[i]=x[i-262143]
    	
    for i in range(262142,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=-1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i]=min(segtree[j],segtree[j+1])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,1)]
        s=set()
        while qq:
            ii,jj,now,kubun=qq.pop()
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,2*kubun))
                qq.append((ii,jj,2*now+2,2*kubun))
        min_list.append(min(s))
       
    for i in range(262142,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=n+1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i]=max(segtree[j],segtree[j+1])
    
    for i in range(n-k+2):
        qq=[(i,i+k-2,0,1)]
        s=set()
        while qq:
            ii,jj,now,kubun=qq.pop()
            now2=now-kubun+1
            width=262144//kubun
            left=width*now2
            right=width*(now2+1)-1
            if ii<=left and right<=jj:
                s.add(segtree[now])
            elif jj<left or right<ii:
                continue
            else:
                qq.append((ii,jj,2*now+1,2*kubun))
                qq.append((ii,jj,2*now+2,2*kubun))
        max_list.append(max(s))
        
    cnt=0
    flag=[True]*(n-k+1)
    first=False
    for i in range(n-1):
        if x[i]<x[i+1]:
            cnt+=1
        else:
            cnt=0
        if cnt>=k-1:
            if first==False:
                first=True
            else:
                flag[i-k+2]=False
    
    for i in range(1,n-k+1):
        if x[i-1]<min_list[i] and max_list[i]<x[i+k-1]:
            flag[i]=False
            
    print(sum(flag))

if __name__ == '__main__':
	main()