#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5;
int dist[N];
vector<int> open[N], close[N];
int n, k;
bool done[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (auto i = 0; i < (long long)(n); i++) {
    int l, r;
    cin >> l >> r;
    open[l].push_back(i);
    close[r + 1].push_back(i);
    dist[i] = r + 1;
  }
  set<int> pool;
  set<pair<int, int> > dist_idx;
  vector<int> res;
  for (auto i = 1; i < (long long)(N); i++) {
    for (auto j : close[i]) {
      if (done[j]) continue;
      pool.erase(j);
      dist_idx.erase({dist[j], j});
    }
    for (auto j : open[i]) {
      pool.insert(j);
      dist_idx.insert({dist[j], j});
    }
    while (((int)((pool).size())) > k) {
      auto it = dist_idx.end();
      it--;
      int idx = (*it).second;
      res.push_back(idx + 1);
      dist_idx.erase(it);
      pool.erase(idx);
      done[idx] = true;
    }
  }
  cout << ((int)((res).size())) << '\n';
  for (auto i : res) cout << i << " ";
  cout << '\n';
  return 0;
}
