#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int l[N], r[N];
vector<int> adjL[N];
set<pair<int, int> > s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < int(n); i++) {
    cin >> l[i] >> r[i];
    adjL[l[i]].push_back(i);
  }
  vector<int> ans;
  for (int i = 0; i < int(N); i++) {
    for (auto nxt : adjL[i]) {
      s.insert({r[nxt], nxt});
    }
    while (int(s.size()) > k) {
      ans.push_back(s.rbegin()->second);
      s.erase(prev(s.end()));
    }
    while (!s.empty() && i == s.begin()->first) s.erase(s.begin());
  }
  cout << int(ans.size()) << '\n';
  for (int id : ans) cout << id + 1 << " ";
  return 0;
}
