import sys def input(): return sys.stdin.readline().rstrip() class Seg: def __init__(self, N): self.N = 1 << (N.bit_length()) self.arr = [0]*(2*self.N) def set(self, i, v): i += self.N self.arr[i] = v while i > 1: i //= 2 self.arr[i] = self.arr[2*i] + self.arr[2*i+1] def get(self, a, b): a += self.N b += self.N ans = 0 while a <= b: if a % 2 == 1: ans += self.arr[a] a += 1 if b % 2 == 0: ans += self.arr[b] b -= 1 a //= 2 b //= 2 return ans def main(): N, K = map(int, input().split()) W = [int(input()) for i in range(N)] MAX = 1000000 seg = Seg(MAX) for i in W: if i < 0: seg.set(-i, max(0, seg.get(-i, -i)-1)) elif seg.get(i, MAX) < K: seg.set(i, seg.get(i, i)+1) print(seg.get(1, MAX)) if __name__ == '__main__': main()