#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Seg {
  int s, t, n;
  Seg(int s = 0, int t = 0, int n = 0) : s(s), t(t), n(n) {}
  bool operator<(const Seg& rhs) const {
    return t == rhs.t ? n < rhs.n : t < rhs.t;
  }
  void print() const { cout << s << " " << t << " " << n << endl; }
};
bool cmp(const Seg& lhs, const Seg& rhs) { return lhs.s < rhs.s; }
int main() {
  int n, k;
  cin >> n >> k;
  set<Seg> S;
  vector<Seg> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].s >> v[i].t;
    v[i].n = i + 1;
  }
  vector<int> removed;
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < (int)v.size(); i++) {
    auto& seg = v[i];
    while (S.size() && S.begin()->t < seg.s) S.erase(S.begin());
    S.insert(seg);
    if ((int)S.size() > k) {
      auto it = S.end();
      --it;
      removed.push_back(it->n);
      S.erase(it);
    }
  }
  sort(removed.begin(), removed.end());
  cout << removed.size() << endl;
  for (auto& it : removed) cout << it << ' ';
  cout << endl;
}
