#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
  int l, r, id;
} a[maxn];
bool cmp(node a, node b) { return a.l < b.l; }
multiset<pair<int, int> > s;
vector<int> ans;
int main() {
  multiset<pair<int, int> >::iterator it;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].l >> a[i].r;
    a[i].id = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    while (s.size() && (*s.begin()).first < a[i].l) s.erase(s.begin());
    s.insert(make_pair(a[i].r, a[i].id));
    while (s.size() > k) {
      multiset<pair<int, int> >::iterator it;
      it = s.end();
      it--;
      ans.push_back((*it).second);
      s.erase(it);
    }
  }
  int len = ans.size();
  cout << len << endl;
  for (int i = 0; i < len; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
