#include <bits/stdc++.h>
using namespace std;
const int MAX = 2 * 1e5 + 2;
vector<vector<pair<int, int>>> d(MAX), z(MAX);
set<pair<int, int>> s;
vector<int> ans;
int n, k;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    d[l].push_back({r, i});
    z[r + 1].push_back({r, i});
  }
  for (int i = 0; i < MAX; ++i) {
    for (auto j : d[i]) s.insert(j);
    for (auto j : z[i]) s.erase(j);
    while (s.size() > k) {
      ans.push_back((*--s.end()).second + 1);
      s.erase(--s.end());
    }
  }
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}
