#include <bits/stdc++.h>
using namespace std;
struct range {
  int l, r, i;
};
bool cmp(range a, range b) { return a.l < b.l; }
class cmp2 {
 public:
  bool operator()(range a, range b) { return a.r > b.r; }
};
int main() {
  int n, k, pos = 0;
  scanf("%d %d", &n, &k);
  range a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i].l, &a[i].r);
    a[i].i = i;
  }
  sort(a, a + n, cmp);
  multiset<range, cmp2> s;
  vector<int> v;
  for (int i = 0; i <= 200000; i++) {
    while (pos < n && a[pos].l == i) {
      s.emplace(a[pos]);
      pos++;
    }
    while (!s.empty() && prev(s.end())->r < i) {
      s.erase(prev(s.end()));
    }
    while (s.size() > k) {
      v.push_back(s.begin()->i);
      s.erase(s.begin());
    }
  }
  printf("%d\n", v.size());
  for (auto e : v) printf("%d ", e + 1);
}
