#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > segs(n);
  vector<vector<int> > ev(N);
  vector<int> cnt(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 + 1 < N; ++i) {
    cnt[i + 1] += cnt[i];
  }
  vector<int> ans(n), sub(N);
  set<pair<int, int> > curSegs;
  int curSub = 0;
  for (int i = 0; i < N; ++i) {
    curSub += sub[i];
    for (auto it : ev[i]) {
      if (it > 0) {
        curSegs.insert({segs[it - 1].second, it - 1});
      } else {
        auto iter = curSegs.find({segs[-it - 1].second, -it - 1});
        if (iter != curSegs.end()) curSegs.erase(iter);
      }
    }
    while (cnt[i] - curSub > k) {
      assert(!curSegs.empty());
      int pos = curSegs.rbegin()->second;
      curSegs.erase(prev(curSegs.end()));
      ++curSub;
      --sub[segs[pos].second + 1];
      ans[pos] = 1;
    }
  }
  cout << accumulate(ans.begin(), ans.end(), 0) << "\n";
  for (int i = 0; i < n; ++i) {
    if (ans[i]) cout << i + 1 << " ";
  }
  cout << "\n";
  return 0;
}
