#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 3;
vector<long long> in[N], out[N];
long long l[N], r[N];
set<pair<long long, long long> > s;
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    in[l[i]].push_back(i);
    out[r[i] + 1].push_back(i);
  }
  vector<long long> res;
  for (long long i = 1; i < N; i++) {
    for (auto j : in[i]) s.insert({r[j], j});
    for (auto j : out[i]) s.erase({r[j], j});
    while ((long long)s.size() > k) {
      auto it = s.end();
      it--;
      res.push_back((*it).second);
      s.erase(it);
    }
  }
  cout << res.size() << endl;
  for (auto i : res) cout << i << " ";
  return 0;
}
