#include <bits/stdc++.h>
using std::bitset;
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::fill;
using std::lower_bound;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::upper_bound;
using std::vector;
const int maxn = 200000 + 10;
struct node {
  int id;
  int l;
  int r;
};
node a[maxn];
bool del[maxn];
std::list<int> ban_list;
struct cmp {
  bool operator()(const node lhs, const node rhs) const {
    return lhs.r < rhs.r;
  }
};
int main(int argc, char** argv) {
  if (argc == 2 && strcmp(argv[1], "-debug") == 0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n, k;
  scanf("%d%d", &n, &k);
  int max = 0;
  for (int i = 0; i < n; i++) {
    a[i].id = i;
    scanf("%d%d", &a[i].l, &a[i].r);
    max = std::max(max, a[i].r);
  }
  std::multiset<node, cmp> s;
  sort(a, a + n, [](const node lhs, const node rhs) {
    return lhs.l == rhs.l ? lhs.r > rhs.r : lhs.l < rhs.l;
  });
  int now = 0;
  for (int i = 1; i <= max; i++) {
    auto it = s.begin();
    while ((int)s.size() > 0 && it->r < i) {
      it = s.erase(it);
    }
    while (now < n && a[now].l == i) {
      s.insert(a[now]);
      ++now;
    }
    if (s.size() == 0) continue;
    it = s.end();
    --it;
    while ((int)s.size() > k) {
      ban_list.push_back(it->id);
      s.erase(it);
      if ((int)s.size() <= k) break;
      it = s.end();
      --it;
    }
  }
  printf("%u\n", ban_list.size());
  for (int i : ban_list) printf("%d ", i + 1);
  return 0;
}
