#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, l, r[200005], cnt = 0;
  bool valid[200005];
  pair<int, int> p;
  pair<int, pair<int, int> > u;
  vector<int> v;
  vector<pair<int, pair<int, int> > > event;
  priority_queue<pair<int, int> > pq;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &l, &r[i]);
    event.push_back(make_pair(l, make_pair(0, i)));
    event.push_back(make_pair(r[i] + 1, make_pair(1, i)));
  }
  sort(event.begin(), event.end());
  memset(valid, true, sizeof valid);
  for (int i = 0; i < (int)event.size(); i++) {
    u = event[i];
    l = u.first;
    while (u.first == l) {
      if (u.second.first == 0) {
        pq.push(make_pair(r[u.second.second], u.second.second));
        cnt++;
      } else if (valid[u.second.second]) {
        valid[u.second.second] = false;
        cnt--;
      }
      i++;
      if (i == (int)event.size()) break;
      u = event[i];
    }
    i--;
    while (cnt > k) {
      p = pq.top();
      pq.pop();
      while (!valid[p.second]) {
        p = pq.top();
        pq.pop();
      }
      valid[p.second] = false;
      v.push_back(p.second);
      cnt--;
    }
  }
  printf("%d\n", (int)v.size());
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) putchar(' ');
    printf("%d", v[i]);
  }
  puts("");
  return 0;
}
