#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
pair<int, int> l[maxn], r[maxn];
bool vis[maxn];
int n, k;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    l[i] = {x, i};
    r[i] = {y, i};
  }
  sort(l + 1, l + n + 1);
  int i1 = 1;
  set<pair<int, int> > q;
  int cnt = 0;
  for (int i = 1; i <= 2e5; i++) {
    while (i1 <= n && l[i1].first == i) {
      cnt++;
      q.insert(r[l[i1].second]);
      i1++;
    }
    while (!q.empty()) {
      auto x = q.begin();
      if (x->first + 1 == i) {
        q.erase(x);
        cnt--;
      } else
        break;
    }
    while (cnt > k) {
      auto x = q.end();
      x--;
      vis[x->second] = 1;
      q.erase(x);
      cnt--;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++)
    if (vis[i]) cout << i << ' ';
  return 0;
}
