#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
struct node {
  int l, r, id;
};
node q[maxn];
int cnt[maxn];
priority_queue<node> que;
vector<int> v;
int cmp(node a, node b) { return a.l < b.l; }
bool operator<(node a, node b) { return a.r < b.r; }
int main() {
  node e;
  int n, k, i, r, now, ans, t, p;
  scanf("%d%d", &n, &k);
  r = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    r = max(r, q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + n + 1, cmp);
  memset(cnt, 0, sizeof(cnt));
  now = 0;
  p = 1;
  ans = 0;
  v.clear();
  for (i = 1; i <= r; i++) {
    now += cnt[i];
    while (p <= n && q[p].l <= i) {
      que.push(q[p]);
      now++;
      cnt[q[p].r + 1]--;
      p++;
    }
    while (!que.empty() && que.top().r < i) {
      que.pop();
    }
    if (now > k) {
      t = now - k;
      while (t--) {
        e = que.top();
        cnt[e.r + 1]++;
        ans++;
        now--;
        v.push_back(e.id);
        que.pop();
      }
    }
  }
  sort(v.begin(), v.end());
  printf("%d\n", ans);
  for (i = 0; i < ans; i++) {
    printf("%d ", v[i]);
  }
  printf("\n");
  return 0;
}
