#include <bits/stdc++.h>
using namespace std;
int n, k;
int l[200000], r[200000];
vector<int> solve() {
  vector<pair<int, int>> segments;
  for (int i = 0; i < n; ++i) {
    segments.push_back({l[i], -(i + 1)});
    segments.push_back({r[i], i + 1});
  }
  sort(segments.begin(), segments.end());
  vector<int> result;
  map<int, int> segment_map;
  priority_queue<pair<int, int>> pq;
  for (pair<int, int> &segment : segments) {
    int x = segment.first, index = segment.second;
    if (index < 0) {
      segment_map[-index] = x;
      pq.push({r[-index - 1], -index});
    } else {
      segment_map.erase(index);
    }
    while (segment_map.size() > k) {
      pair<int, int> s = pq.top();
      if (segment_map.count(s.second) > 0) {
        segment_map.erase(s.second);
        result.push_back(s.second);
      }
      pq.pop();
    }
  }
  return result;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &l[i], &r[i]);
  }
  vector<int> result = solve();
  printf("%d\n", result.size());
  for (int value : result) {
    printf("%d ", value);
  }
  printf("\n");
  return 0;
}
