#include <bits/stdc++.h>
using namespace std;
vector<int> t[100001 * 2];
set<pair<int, int> > se;
int main() {
  ios_base::sync_with_stdio(0);
  istream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int x[n + 1], y[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    t[x[i]].push_back(i);
    t[y[i] + 1].push_back(-i);
  }
  vector<int> g;
  g.clear();
  for (int i = 1; i <= 200000; i++) {
    for (auto nxt : t[i]) {
      if (nxt < 0) {
        if (se.find({-y[-nxt], -nxt}) != se.end()) se.erase({-y[-nxt], -nxt});
      } else
        se.insert({-y[nxt], nxt});
    }
    while (int(se.size()) > k) {
      g.push_back((*se.begin()).second);
      se.erase(se.begin());
    }
  }
  cout << g.size() << endl;
  for (auto nxt : g) {
    cout << nxt << " ";
  }
}
