#include <bits/stdc++.h>
using namespace std;
const int inf = 2e5 + 9;
int n, k;
vector<int> ans;
pair<pair<int, int>, int> a[inf];
set<pair<int, int> > add[inf], cur, del[inf];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = make_pair(make_pair(x, y), i);
    add[x].insert(make_pair(y, i));
    del[y].insert(make_pair(y, i));
  }
  sort(a + 1, a + 1 + n);
  int cnt = 0;
  for (int i = 1; i < inf; i++) {
    cnt += add[i].size();
    for (auto o : add[i]) cur.insert(o);
    while (cnt > k) {
      auto o = *cur.rbegin();
      cur.erase(o);
      cnt--;
      ans.push_back(o.second);
      del[o.first].erase(o);
    }
    cnt -= del[i].size();
    for (auto o : del[i]) cur.erase(o);
  }
  cout << ans.size() << endl;
  for (auto o : ans) cout << o << " ";
  cout << endl;
}
