#include <bits/stdc++.h>
using namespace std;
int Read() {
  int Output = 0;
  char Input = getchar();
  while (Input < '0' || Input > '9') Input = getchar();
  while (Input >= '0' && Input <= '9') {
    Output = (Output << 3) + (Output << 1) + Input - '0';
    Input = getchar();
  }
  return Output;
}
int N, K;
int Count[200001];
struct line {
  int L, R, Pos;
  bool operator<(const line &A) const { return A.R > R; }
} Line[200001];
int Now;
int Num = 1;
int Ans[200001];
int Total;
priority_queue<line> Q;
bool Cmp(line A, line B) { return A.L < B.L; }
int main() {
  N = Read(), K = Read();
  for (int i = 1; i <= N; ++i) {
    Line[i].L = Read();
    Line[i].R = Read();
    ++Count[Line[i].L - 1];
    --Count[Line[i].R];
    Line[i].Pos = i;
  }
  sort(Line + 1, Line + N + 1, Cmp);
  Now = Count[0];
  for (int i = 1; i <= 2e5; ++i) {
    while (Line[Num].L == i) {
      Q.push(Line[Num]);
      ++Num;
    }
    while (Now > K) {
      --Now;
      line Top = Q.top();
      Ans[++Total] = Top.Pos;
      ++Count[Top.R];
      --Count[Top.L - 1];
      Q.pop();
    }
    Now += Count[i];
  }
  printf("%d\n", Total);
  sort(Ans + 1, Ans + Total + 1);
  for (int i = 1; i <= Total; ++i) printf("%d ", Ans[i]);
  return 0;
}
