#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 2e5 + 1;
const int oo = 1e9;
const double pi = acos(-1);
struct seg {
  int left, right, idx;
};
bool comp1(seg a, seg b) {
  return a.left < b.left || (a.left == b.left && a.right < b.right) ||
         (a.left == b.left && a.right == b.right && a.idx < b.idx);
}
bool comp2(seg a, seg b) {
  return a.right < b.right || (a.right == b.right && a.left < b.left) ||
         (a.right == b.right && a.left == b.left && a.idx < b.idx);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<seg> minL(n), minR(n);
  for (int i = 0; i < n; ++i) {
    cin >> minL[i].left >> minL[i].right;
    minL[i].idx = i + 1;
    minR[i] = minL[i];
  }
  sort(minL.begin(), minL.end(), comp1);
  sort(minR.begin(), minR.end(), comp2);
  vector<int> ans;
  set<pair<pair<int, int>, int>> active;
  for (int p = 1, i = 0, j = 0; p < N; ++p) {
    while (i < n && minL[i].left <= p) {
      active.insert({{minL[i].right, minL[i].left}, minL[i].idx});
      ++i;
    }
    while (active.size() > k) {
      auto best = active.end();
      --best;
      ans.push_back(best->second);
      active.erase(best);
    }
    while (j < n && minR[j].right <= p) {
      active.erase({{minR[j].right, minR[j].left}, minR[j].idx});
      ++j;
    }
  }
  cout << ans.size() << endl;
  for (auto a : ans) cout << a << " ";
  cout << endl;
  return 0;
}
