class FenwickTree: # (BinaryIndexedTree) def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): out = 0 while i > 0: out += self.tree[i] i -= (i & -i) return out def add(self, i, x): while i <= self.size: self.tree[i] += x i += (i & -i) N,K = map(int,input().split()) M = 100001 BIT = FenwickTree(M) for _ in range(N): W = int(input()) if W > 0: # 荷物を積む cnt = BIT.sum(M) - (BIT.sum(W - 1) if W > 1 else 0) # その荷物以上の荷物の重さ if cnt < K: # 積める BIT.add(W, 1) else: # 荷物を下ろす W *= (-1) cnt = BIT.sum(W) - (BIT.sum(W - 1) if W > 1 else 0) if cnt > 0: BIT.add(W, -1) print(BIT.sum(M))