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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
static const int maxn = 2e5 + 5;
struct data {
  long long int sum;
  data() : sum(0) {}
};
long long int store[maxn];
struct SegTree {
  int N;
  vector<data> st;
  vector<bool> cLazy;
  vector<long long int> lazy;
  void init(int n) {
    N = n;
    st.resize(4 * N + 5);
    cLazy.resize(4 * N + 5);
    lazy.resize(4 * N + 5);
  }
  void merge(data &cur, data &l, data &r) { cur.sum = max(l.sum, r.sum); }
  void propagate(int node, int L, int R) {
    if (L != R) {
      int lft = node * 2;
      int rgt = lft + 1;
      cLazy[lft] = 1;
      cLazy[rgt] = 1;
      lazy[lft] = lazy[lft] + lazy[node];
      lazy[rgt] = lazy[rgt] + lazy[node];
    }
    st[node].sum = st[node].sum + lazy[node];
    cLazy[node] = 0;
    lazy[node] = 0;
  }
  void build(int node, int L, int R) {
    if (L == R) {
      st[node].sum = store[L];
      cLazy[node] = 0;
      lazy[node] = 0;
      return;
    }
    int lft = node * 2;
    int rgt = lft + 1;
    int M = (L + R) / 2;
    build(lft, L, M);
    build(rgt, M + 1, R);
    merge(st[node], st[lft], st[rgt]);
  }
  data Query(int node, int L, int R, int i, int j) {
    if (cLazy[node]) propagate(node, L, R);
    if (j < L || i > R) return data();
    if (i <= L && R <= j) return st[node];
    int lft = node * 2;
    int rgt = lft + 1;
    int M = (L + R) / 2;
    data p = Query(lft, L, M, i, j);
    data q = Query(rgt, M + 1, R, i, j);
    data cur;
    merge(cur, p, q);
    return cur;
  }
  data pQuery(int node, int L, int R, int pos) {
    if (cLazy[node]) propagate(node, L, R);
    if (L == R) return st[node];
    int lft = node * 2;
    int rgt = lft + 1;
    int M = (L + R) / 2;
    if (pos <= M)
      return pQuery(lft, L, M, pos);
    else
      return pQuery(rgt, M + 1, R, pos);
  }
  void update(int node, int L, int R, int i, int j, long long int val) {
    if (cLazy[node]) propagate(node, L, R);
    if (j < L || i > R) return;
    if (i <= L && R <= j) {
      cLazy[node] = 1;
      lazy[node] = lazy[node] + val;
      propagate(node, L, R);
      return;
    }
    int lft = node * 2;
    int rgt = lft + 1;
    int M = (L + R) / 2;
    update(lft, L, M, i, j, val);
    update(rgt, M + 1, R, i, j, val);
    merge(st[node], st[lft], st[rgt]);
  }
  void pUpdate(int node, int L, int R, int pos, long long int val) {
    if (cLazy[node]) propagate(node, L, R);
    if (L == R) {
      cLazy[node] = 1;
      lazy[node] = lazy[node] + val;
      propagate(node, L, R);
      return;
    }
    int lft = node * 2;
    int rgt = lft + 1;
    int M = (L + R) / 2;
    if (pos <= M)
      pUpdate(lft, L, M, pos, val);
    else
      pUpdate(rgt, M + 1, R, pos, val);
    merge(st[node], st[lft], st[rgt]);
  }
  data query(int pos) { return pQuery(1, 1, N, pos); }
  data query(int l, int r) { return Query(1, 1, N, l, r); }
  void update(int pos, long long int val) { pUpdate(1, 1, N, pos, val); }
  void update(int l, int r, long long int val) { update(1, 1, N, l, r, val); }
};
int l[maxn];
int r[maxn];
int segs[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  SegTree Tree;
  int N = 2e5;
  Tree.init(N);
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    segs[i] = i;
  }
  sort(segs + 1, segs + n + 1, [&](int i, int j) { return r[i] < r[j]; });
  vector<int> del;
  for (int i = 1; i <= n; i++) {
    int q = Tree.query(l[segs[i]], r[segs[i]]).sum;
    if (q == k)
      del.push_back(segs[i]);
    else
      Tree.update(l[segs[i]], r[segs[i]], 1);
  }
  cout << del.size() << '\n';
  for (int x : del) cout << x << " ";
}