Problem: The only difference between easy and hard versions is constraints.

You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i.

The integer point is called bad if it is covered by strictly more than k segments.

Your task is to remove the minimum number of segments so that there are no bad points at all.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of segments and the maximum number of segments by which each integer point can be covered.

The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 2 ⋅ 10^5) — the endpoints of the i-th segment.

Output

In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points.

In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.

Examples

Input


7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9


Output


3
4 6 7 


Input


5 1
29 30
30 30
29 29
28 30
30 30


Output


3
1 4 5 


Input


6 1
2 3
3 3
2 3
2 2
2 3
2 3


Output


4
1 3 5 6 

Solution (in JAVA):

Solution:
'use strict'

const SegTreeIndex = (n) => {
    const self = { n: 1 };
    while (self.n < n) self.n <<= 1;
    self.tree = Array(self.n << 1).fill(-1);
    self.index = Array(self.n << 1).fill(-1);
    for (let i = 0; i < self.n; i++) self.index[i + self.n] = i;
    for (let i = self.n - 1; i; i--) self.index[i] = self.index[i << 1];

    self.update = (i, x) => {
        i += self.n;
        self.tree[i] = x;
        while (i > 1) {
            const left = Math.min(i, i^1);
            const right = Math.max(i, i^1);
            if (self.tree[left] >= self.tree[right]) {
                self.tree[i >> 1] = self.tree[left];
                self.index[i >> 1] = self.index[left];
            } else {
                self.tree[i >> 1] = self.tree[right];
                self.index[i >> 1] = self.index[right];
            }
            i >>= 1;
        }
    }

    self.query = (a, b) => {
        let l = a + self.n;
        let r = b + self.n;
        let s = [ -1, -1 ];
        while (l < r) {
            if (r & 1) {
                r -= 1;
                const res = Math.max(s[0], self.tree[r]);
                if (res !== s[0]) s = [ self.tree[r], self.index[r] ];
            }
            if (l & 1) {
                const res = Math.max(self.tree[l], s[0])
                if (res === self.tree[l]) s = [ self.tree[l], self.index[l] ];
                l += 1;
            }
            l >>= 1;
            r >>= 1;
        }
        return s
    }
    return self;
}

const NK = readline().split(' ').map(Number);
const N = NK[0];
const K = NK[1];
const MAX = 200001;

const LRs = Array.from({ length: MAX+2 }, () => []);
const R = Array.from({ length: N+1 }, () => 0);

for (let i = 0; i < N; i++) {
    const lr = readline().split(' ').map(Number);
    const l = lr[0];
    const r = lr[1];
    LRs[l].push(i+1)
    LRs[r+1].push(-(i+1))
    R[i+1] = r;
}

const sti = SegTreeIndex(N+1)

let segcnt = 0;
let ans = [];
let removed = new Set();

for (let i = 1; i < MAX+2; i++) {
    LRs[i].forEach(idx => {
        if (idx > 0) {
            sti.update(idx, R[idx]);
            segcnt += 1;
        } else {
            const idx2 = -idx;
            if (!removed.has(idx2)) {
                sti.update(idx2, -1);
                segcnt -= 1;
            }
        }
    })
    while (segcnt > K) {
        const query = sti.query(0, N+1);
        const mx = query[0];
        const idx = query[1];
        sti.update(idx, -1);
        ans.push(idx);
        removed.add(idx);
        segcnt -= 1;
    }
}
print(ans.length);
print(ans.join(' '));