#include <bits/stdc++.h>
using namespace std;
int n, k, vis[200024], sum, maxr, x, y, Ans[200024], cnt;
struct info {
  int l, r, id;
} q[200024];
bool operator<(info A, info B) { return A.r < B.r; }
vector<info> G[200024];
int Read() {
  int num = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    num = (num << 3) + (num << 1) + c - 48, c = getchar();
  return num;
}
int main() {
  n = Read(), k = Read();
  for (int i = 1; i <= n; i++) {
    x = Read(), y = Read();
    vis[x]++;
    vis[y + 1]--;
    maxr = max(maxr, y);
    G[x].push_back({x, y, i});
  }
  priority_queue<info> q;
  for (int i = 1; i <= maxr; i++) {
    sum += vis[i];
    for (int j = G[i].size(); j; j--) q.push(G[i][j - 1]);
    while (sum > k) {
      info now = q.top();
      q.pop();
      Ans[++cnt] = now.id;
      sum--;
      vis[now.r + 1]++;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", Ans[i]);
}
