#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<tuple<int, int, int> > segments(n);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    segments[i] = {l, r, i};
  }
  sort(segments.begin(), segments.end());
  set<tuple<int, int, int> > active;
  int i = 0;
  vector<int> removed;
  while (i < n) {
    int curr_x = get<0>(segments[i]);
    while (i < n && get<0>(segments[i]) == curr_x) {
      active.insert(
          {get<1>(segments[i]), get<0>(segments[i]), get<2>(segments[i])});
      i++;
    }
    while (active.size() > 0 && get<0>(*(active.begin())) < curr_x)
      active.erase(active.begin());
    while (active.size() > k) {
      auto it = active.end();
      it--;
      removed.push_back(get<2>(*it));
      active.erase(it);
    }
    while (active.size() > 0 && get<0>(*(active.begin())) == curr_x)
      active.erase(active.begin());
  }
  cout << removed.size() << '\n';
  for (int i : removed) cout << i + 1 << ' ';
  cout << '\n';
  return 0;
}
