#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 7;
int N, K;
struct node {
  int r, id;
  node(int b = 0, int c = 0) : r(b), id(c) {}
  friend bool operator<(node e1, node e2) { return e1.r < e2.r; }
};
vector<node> add[maxN], del[maxN];
multiset<node> now;
multiset<node>::iterator it;
vector<int> vt;
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 1, l, r; i <= N; i++) {
    scanf("%d%d", &l, &r);
    add[l].push_back(node(r, i));
    del[r + 1].push_back(node(r, i));
  }
  for (int i = 1; i <= 200000; i++) {
    int len = (int)add[i].size();
    for (int j = 0; j < len; j++) now.insert(add[i][j]);
    len = (int)del[i].size();
    for (int j = 0; j < len; j++) now.erase(del[i][j]);
    len = (int)now.size();
    if (len > K) {
      int det = len - K;
      while (det) {
        it = now.end();
        vt.push_back((--it)->id);
        now.erase(it);
        det--;
      }
    }
  }
  int len = (int)vt.size();
  printf("%d\n", len);
  for (int i = 0; i < len; i++) printf("%d ", vt[i]);
  printf("\n");
  return 0;
}
