#include <bits/stdc++.h>
using namespace std;
set<pair<int, int>> q;
set<pair<int, int>> q1;
vector<pair<int, int>> mas[200010];
void MakeGood(int lst) {
  auto x = q.end();
  int r = q.size();
  vector<pair<int, int>> tod;
  while (r > 0) {
    r--;
    x--;
    if (x->first <= lst) {
      break;
    } else {
      tod.push_back(*x);
    }
  }
  for (auto p : tod) {
    q.erase(p);
  }
}
vector<int> ans;
int main() {
  int n, k;
  cin >> n >> k;
  int u, v;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &u, &v);
    mas[v].push_back({u, i});
  }
  for (int i = 200005; i >= 0; i--) {
    MakeGood(i);
    for (auto x : mas[i]) {
      q.insert(x);
    }
    while (q.size() > k) {
      ans.push_back((q.begin())->second + 1);
      q.erase(*(q.begin()));
    }
  }
  cout << ans.size() << endl;
  for (auto x : ans) {
    printf("%d ", x);
  }
  cout << endl;
}
