#include <bits/stdc++.h>
using namespace std;
void fastInOut();
const int N = 2e5 + 5;
vector<int> st[N], ed[N];
pair<int, int> segs[N];
int main() {
  fastInOut();
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> segs[i].first >> segs[i].second;
    st[segs[i].first].push_back(i);
    ed[segs[i].second].push_back(i);
  }
  set<pair<int, int> > S;
  vector<int> ans;
  for (int i = 0; i < N; ++i) {
    for (int seg : st[i]) S.insert({segs[seg].second, seg});
    while (S.size() > k) {
      auto it = prev(S.end());
      ans.push_back(it->second);
      S.erase(it);
    }
    for (int seg : ed[i]) S.erase({segs[seg].second, seg});
  }
  cout << (int)ans.size() << '\n';
  for (int i : ans) cout << i + 1 << ' ';
  cout << '\n';
  return 0;
}
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
