N, K = map(int, input().split()) P = list(map(int, input().split())) P.sort(reverse=True) if N == K or P[K-1] != P[K]: print(K) else: B = P[K-1] for i in range(K-2, -1, -1): if P[i] != B: print(i+1) break else: print(0)