#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 2;
struct lr {
  int r, id;
  bool operator<(const lr& o) const {
    return r > o.r || (r == o.r && id < o.id);
  }
};
int n, k;
vector<lr> p[N];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1, l, r; i <= n; i++) {
    cin >> l >> r;
    p[l].push_back({r, i});
  }
  set<lr> s;
  vector<int> ans;
  for (int i = 1; i < N; i++) {
    while (!s.empty() && (--s.end())->r < i) {
      s.erase(--s.end());
    }
    for (auto& cpi : p[i]) {
      s.insert(cpi);
    }
    while (s.size() > k) {
      auto as = s.begin();
      ans.push_back(as->id);
      s.erase(as);
    }
  }
  cout << ans.size() << '\n';
  for (auto& x : ans) {
    cout << x << ' ';
  }
}
