#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ids_ends[200000 + 10];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int l, r;
    cin >> l >> r;
    ids_ends[l].push_back({r, i});
  }
  vector<int> ans;
  set<pair<int, int>> ids_ends_q;
  for (int pos = 1; pos <= 200000; pos++) {
    for (pair<int, int> id_end : ids_ends[pos]) {
      ids_ends_q.insert(id_end);
    }
    while (ids_ends_q.size() > k) {
      pair<int, int> end_id = *ids_ends_q.rbegin();
      ids_ends_q.erase(end_id);
      ans.push_back(end_id.second);
    }
    while (!ids_ends_q.empty() && ids_ends_q.begin()->first <= pos) {
      ids_ends_q.erase(ids_ends_q.begin());
    }
  }
  cout << ans.size() << endl;
  for (int x : ans) printf("%d ", x);
  cout << endl;
}
