#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 100;
vector<int> ans;
set<pair<int, int>> add[MAX], rem[MAX], cur;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    add[x].insert({y, i});
    rem[y + 1].insert({y, i});
  }
  for (int i = 1; i < MAX; i++) {
    for (auto p : rem[i]) {
      cur.erase(p);
    }
    for (auto p : add[i]) {
      cur.insert(p);
    }
    while (cur.size() > k) {
      set<pair<int, int>>::iterator it;
      it = prev(cur.end());
      ans.push_back((*it).second);
      cur.erase(it);
    }
  }
  cout << ans.size() << endl;
  for (int x : ans) {
    cout << x << " ";
  }
  return 0;
}
