#!/usr/bin/env python3 import collections class FenwickTree(object): def __init__(self, num_elems): self.num_elems = num_elems self.data = [0] * num_elems def sum_to(self, end): s = 0 i = end - 1 while i >= 0: s += self.data[i] i = (i & (i + 1)) - 1 return s def sum_range(self, start, end): return self.sum_to(end) - self.sum_to(start) def add(self, idx, x): while idx < self.num_elems: self.data[idx] += x idx |= idx + 1 def main(): n, k = map(int, input().split()) ws = [int(input()) for _ in range(n)] max_weight = max(map(abs, ws)) packs = collections.Counter() ft = FenwickTree(max_weight + 1) for w in ws: if w > 0 and ft.sum_range(w, max_weight + 1) < k: ft.add(w, 1) packs[w] += 1 elif w < 0 and packs[abs(w)] > 0: ft.add(abs(w), -1) packs[abs(w)] -= 1 print(ft.sum_to(max_weight + 1)) if __name__ == '__main__': main()