#include <bits/stdc++.h>
using namespace std;
struct node {
  int ind, y;
};
bool operator<(node a, node b) {
  if (a.y != b.y)
    return a.y < b.y;
  else
    return a.ind > b.ind;
}
vector<node> ve[200000 + 10];
vector<int> ans;
int main() {
  int x, y, k, n;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    node nd = {i, y};
    ve[x].push_back(nd);
  }
  set<node> st;
  for (int i = 1; i <= 200000; i++) {
    while (st.size() && (*st.begin()).y < i) st.erase(st.begin());
    for (auto it : ve[i]) st.insert(it);
    while (st.size() > k) {
      ans.push_back((*st.rbegin()).ind);
      st.erase(*(st.rbegin()));
    }
  }
  cout << ans.size() << endl;
  for (auto it : ans) cout << it << " ";
  cout << endl;
}
