#include #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair; using VI = vector; using VVI = vector; template struct BIT { int n; vector d; BIT(int n=0):n(n),d(n+1) {} void add(int i, T x=1) { for (i++; i <= n; i += i&-i) { d[i] += x; } } T sum(int i) { T x = 0; for (i++; i; i -= i&-i) { x += d[i]; } return x; } T sum(int l, int r) { return sum(r-1) - sum(l-1); } int operator[](int x) { return sum(x, x + 1); } }; int main() { int n, k; cin >> n >> k; BIT d(1000001); rep(_, n) { int w; cin >> w; if (w > 0) { if (d.sum(w, 1000001) < k) d.add(w); } else { if (d[-w] > 0) d.add(-w, -1); } } cout << d.sum(1000000) << endl; }