#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, id;
  bool operator<(const node &b) const { return r < b.r; }
} a[200009];
bool cmp(node a, node b) {
  if (a.l == b.l) return a.r < b.r;
  return a.l < b.l;
}
int vis[200009] = {}, ans[200009] = {};
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i].l, &a[i].r);
    vis[a[i].l]++;
    vis[a[i].r + 1]--;
    a[i].id = i;
  }
  sort(a, a + n, cmp);
  int j = 0, cnt = 0;
  priority_queue<node> q;
  for (int i = 1; i <= 200000; i++) {
    while (j < n && a[j].l <= i) q.push(a[j++]);
    vis[i] += vis[i - 1];
    while (vis[i] > k) {
      node p = q.top();
      q.pop();
      ans[cnt++] = p.id;
      vis[i]--;
      vis[p.r + 1]++;
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; i++)
    printf("%d%s", ans[i] + 1, i == cnt - 1 ? "\n" : " ");
  return 0;
}
