#include <bits/stdc++.h>
#pragma GCC optimize(8)
using namespace std;
inline void read(int& s) {
  s = 0;
  static char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  return;
}
const int N = 200003;
int k, n, ans, a[N], sum[N], mx;
struct stu {
  int x, y, id;
} s[N], p;
inline int cmp2(const stu p, const stu q) {
  if (p.x == q.x) return p.y < q.y;
  return p.x < q.x;
}
struct cmp {
  inline int operator()(const stu& p, const stu& q) const { return p.y < q.y; }
};
priority_queue<stu, vector<stu>, cmp> q;
int main() {
  read(n), read(k);
  int i;
  for (i = 1; i <= n; ++i) {
    read(s[i].x), read(s[i].y), s[i].id = i;
    ++sum[s[i].x];
    --sum[s[i].y + 1];
  }
  sort(s + 1, s + 1 + n, cmp2);
  int j = 1;
  for (i = 1; i < N; ++i) {
    while (j <= n && s[j].x <= i) q.push(s[j++]);
    sum[i] += sum[i - 1];
    while (sum[i] > k) {
      p = q.top();
      q.pop();
      a[++ans] = p.id;
      --sum[i];
      ++sum[p.y + 1];
    }
  }
  printf("%d\n", ans);
  if (ans) {
    for (i = 1; i < ans; ++i) printf("%d ", a[i]);
    printf("%d\n", a[ans]);
  }
  return 0;
}
