#include <bits/stdc++.h>
using namespace std;
struct segm {
  int l = 0, r = 0, index = 0;
  bool operator<(const segm a) const {
    if (a.l == l) {
      return r < a.r;
    }
    return l < a.l;
  }
};
int n, k;
vector<segm> segms;
set<pair<int, int>> open;
vector<int> ans;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  segm p;
  for (int i = 1; i <= n; i++) {
    cin >> p.l >> p.r;
    p.index = i;
    segms.push_back(p);
  }
  sort(segms.begin(), segms.end());
  for (int i = 0; i < n; i++) {
    while (!open.empty()) {
      if (open.begin()->first >= segms[i].l) {
        break;
      }
      open.erase(open.begin());
    }
    open.insert({segms[i].r, segms[i].index});
    if (open.size() > k) {
      ans.push_back(prev(open.end())->second);
      open.erase(prev(open.end()));
    }
  }
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}
