#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int n, k;
int l[(int)2e5 + 100], r[(int)2e5 + 100], deleted[(int)2e5 + 100] = {0};
struct comper {
  bool operator()(const int& a, const int& b) const {
    if (r[a] == r[b]) return l[a] > l[b];
    return r[a] > r[b];
  }
};
int main() {
  fast();
  cin >> n >> k;
  vector<vector<int> > m1((1 << 20)), m2((1 << 20));
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    m1[l[i]].push_back(i);
    m2[r[i] + 1].push_back(i);
  }
  set<pair<int, int> > s;
  for (int i = 1; i < (int)2e5 + 10; i++) {
    if (!m1[i].empty()) {
      for (int x : m1[i]) s.insert({-r[x], x});
    }
    if (!m2[i].empty()) {
      for (int x : m2[i]) {
        s.erase({-r[x], x});
      }
    }
    while ((int)((s).size()) > k) {
      int idx = (*s.begin()).second;
      deleted[idx] = 1;
      s.erase(s.begin());
    }
  }
  cout << accumulate(deleted, deleted + (int)2e5 + 100, 0) << endl;
  for (int i = 0; i < (int)2e5 + 2; i++)
    if (deleted[i]) cout << i + 1 << " ";
}
