#include <bits/stdc++.h>
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
using namespace std;
const long long maxn = 3e5 + 10;
long long n, m, k;
long long st3[maxn];
struct seg {
  long long l;
  long long r;
  long long i;
};
bool operator<(seg a, seg b) {
  if (a.r == b.r) {
    return a.i < b.i;
  }
  return a.r > b.r;
}
seg A[maxn];
vector<seg> L[maxn];
vector<seg> R[maxn];
set<seg> S;
vector<long long> ANS;
signed main() {
  long long q, w, e, a, b, c;
  cin >> n >> k;
  for (q = 0; q < n; q++) {
    cin >> A[q].l >> A[q].r;
    A[q].i = q;
    L[A[q].l].push_back(A[q]);
    R[A[q].r].push_back(A[q]);
  }
  for (q = 0; q < maxn; q++) {
    for (w = 0; w < L[q].size(); w++) {
      S.insert(L[q][w]);
    }
    while (S.size() > k) {
      seg del = *(S.begin());
      ANS.push_back(del.i);
      S.erase(S.begin());
    }
    for (w = 0; w < R[q].size(); w++) {
      S.erase(R[q][w]);
    }
  }
  cout << ANS.size() << endl;
  for (q = 0; q < ANS.size(); q++) {
    cout << ANS[q] + 1 << " ";
  }
}
