#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 15;
const int MOD = 1000000007;
const int inf = 0x3f3f3f3f;
struct Seg {
  int l, r, idx;
  bool operator<(const Seg& b) const { return l != b.l ? l < b.l : r < b.r; }
};
Seg seg[N];
int sum[N];
bool used[N];
int main() {
  int k, n;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &seg[i].l, &seg[i].r);
    seg[i].idx = i;
  }
  sort(seg + 1, seg + 1 + n);
  int m = 0;
  priority_queue<pair<int, int> > que;
  for (int i = 1, it = 1; i <= N - 1; i++) {
    while (it <= n && seg[it].l == i) {
      que.push(make_pair(seg[it].r, seg[it].idx));
      sum[i]++;
      sum[seg[it].r + 1]--;
      it++;
    }
    sum[i] += sum[i - 1];
    while (sum[i] > k) {
      auto pr = que.top();
      que.pop();
      used[pr.second] = true;
      sum[i]--;
      sum[pr.first + 1]++;
      m++;
    }
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++) {
    if (used[i]) {
      printf("%d ", i);
    }
  }
  puts("");
}
