#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<pair<int, int> > l[N], r[N];
priority_queue<pair<int, int> > q;
vector<int> ans;
int d[N], e[N];
bool cmp(pair<int, int> x, pair<int, int> y) { return x.first > y.first; }
int main() {
  int n, k, maxn = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    maxn = max(maxn, y);
    l[x].push_back(make_pair(y, i));
    r[y].push_back(make_pair(x, i));
  }
  int t = 0;
  for (int i = maxn; i >= 1; i--) {
    if (r[i].size()) {
      for (auto v : r[i]) {
        t++;
        q.push(make_pair(-v.first, v.second));
      }
      while (!q.empty() && q.size() && t > k) {
        while (e[q.top().second]) q.pop();
        pair<int, int> now = q.top();
        q.pop();
        ans.push_back(now.second);
        d[now.second] = 1;
        t--;
      }
    }
    if (l[i].size()) {
      for (auto v : l[i]) {
        if (d[v.second]) continue;
        t--;
        e[v.second] = 1;
      }
    }
  }
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  if (!ans.empty())
    for (auto v : ans) {
      printf("%d ", v);
    }
  return 0;
}
