#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int d[N];
struct Segment {
  int l, r, id;
  bool operator<(const Segment &o) const { return r < o.r; }
} seg[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    seg[i].l = l, seg[i].r = r;
    seg[i].id = i;
    d[l]++;
    d[r + 1]--;
  }
  auto cmp = [](const Segment &a, const Segment &b) { return a.l < b.l; };
  sort(seg + 1, seg + n + 1, cmp);
  multiset<Segment> o;
  int sum = 0;
  int maxn = 2e5;
  int p = 1;
  vector<int> bestid;
  for (int i = 1; i <= maxn; ++i) {
    sum += d[i];
    while (p <= n && seg[p].l <= i) {
      o.insert(seg[p]);
      ++p;
    }
    while (sum > k) {
      auto it = o.end();
      --it;
      bestid.push_back(it->id);
      d[it->r + 1]++;
      sum--;
      o.erase(it);
    }
  }
  sort(bestid.begin(), bestid.end());
  printf("%d\n", int(bestid.size()));
  for (int &v : bestid) printf("%d ", v);
  puts("");
}
