#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k, l[maxn], r[maxn], c[2 * maxn], tot = 0, o[2 * maxn], oo[2 * maxn];
struct line {
  int l, r, id;
  friend bool operator<(const line &a, const line &b) { return a.r < b.r; }
} d[maxn];
int sta[maxn], cnt = 0;
vector<pair<int, int> > vec[2 * maxn];
priority_queue<line> que;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &l[i], &r[i]);
    vec[l[i]].push_back(make_pair(i, r[i]));
    o[l[i]]++, o[r[i] + 1]--;
  }
  for (int i = 1; i < maxn; i++) o[i] += o[i - 1];
  for (int i = 1; i < maxn; i++) {
    oo[i] += oo[i - 1];
    for (int j = 0; j < vec[i].size(); j++) {
      que.push(line{i, vec[i][j].second, vec[i][j].first});
    }
    if (o[i] - oo[i] > k) {
      int t = o[i] - oo[i] - k;
      for (int j = 1; j <= t; j++) {
        line cur = que.top();
        que.pop();
        sta[++cnt] = cur.id;
        oo[i]++;
        oo[cur.r + 1]--;
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d%c", sta[i], i == cnt ? '\n' : ' ');
}
