#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<pair<int, int>, int> a[200005];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first.first >> a[i].first.second;
    a[i].second = i + 1;
  }
  sort(a, a + n);
  multiset<pair<int, int> > s;
  int r = 0;
  vector<int> v;
  for (int i = 1; i <= 200000; i++) {
    while (r < n && a[r].first.first <= i) {
      s.insert({a[r].first.second, a[r].second});
      r++;
    }
    while (true) {
      if (s.empty()) break;
      auto it = s.begin();
      int id = (*it).first;
      if (id < i)
        s.erase(it);
      else
        break;
    }
    int size = s.size();
    if (size <= k) continue;
    while (size > k) {
      auto it = s.end();
      it--;
      int id = (*it).second;
      v.push_back(id);
      s.erase(it);
      size--;
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ');
  }
  return 0;
}
