#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> segs(n);
  vector<int> cnt(N);
  vector<vector<int>> ev(N);
  for (int i = 0; i < n; i++) {
    cin >> segs[i].first >> segs[i].second;
    ++cnt[segs[i].first];
    --cnt[segs[i].second + 1];
    ev[segs[i].first].push_back(i + 1);
    ev[segs[i].second + 1].push_back(-i - 1);
  }
  for (int i = 0; i < N - 1; i++) cnt[i + 1] += cnt[i];
  set<pair<int, int>> curSegs;
  int curSeg = 0;
  vector<int> ans(n), Sub(N);
  for (int i = 0; i < N; i++) {
    curSeg += Sub[i];
    for (auto it : ev[i]) {
      if (it > 0) {
        curSegs.insert(make_pair(segs[it - 1].second, it - 1));
      } else {
        auto sd = curSegs.find(make_pair(segs[-it - 1].second, -it - 1));
        if (sd != curSegs.end()) curSegs.erase(sd);
      }
    }
    while (cnt[i] - curSeg > k) {
      assert(!curSegs.empty());
      int pos = curSegs.rbegin()->second;
      curSegs.erase(prev(curSegs.end()));
      curSeg++;
      --Sub[segs[pos].second + 1];
      ans[pos] = 1;
    }
  }
  cout << accumulate(ans.begin(), ans.end(), 0) << endl;
  for (int i = 0; i < n; i++)
    if (ans[i]) cout << i + 1 << " ";
  return 0;
}
