import java.util.*; public class Main { static int N; static int[] dat; public static void main(String[] args) { Scanner sc = new Scanner(System.in); init(1000001); int n = sc.nextInt(); int k = sc.nextInt(); int ans = 0; for(int i = 0; i < n; i++) { int w = sc.nextInt(); if(w > 0) { int t = query(w, dat.length, 0, 0, N); if(t < k) { update(w, 1); ans++; } } else { if(dat[(-1) * w + N - 1] > 0) { update((-1) * w, -1); ans--; } } } System.out.println(ans); } public static void init(int n_) { int n = 1; while(n < n_) { n *= 2; } N = n; dat = new int[2 * N - 1]; } public static void update(int k, int x) { int a = k + N - 1; dat[a] += x; while(a > 0) { a = (a - 1) / 2; dat[a] = dat[2 * a + 1] + dat[2 * a + 2]; } } public static int query(int a, int b, int k, int l, int r) { if((r <= a) || (l >= b)) return 0; if((a <= l) && (r <= b)) { return dat[k]; } else { int vl = query(a, b, 2 * k + 1, l, (l + r) / 2); int vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } } }