#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long n, pos[N], k, del[N];
bool take[N];
pair<long long, long long> dot[N];
vector<long long> ocur[N];
vector<long long> ans;
set<pair<long long, long long> > heap;
void In() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> dot[i].first >> dot[i].second;
    pos[dot[i].first]++;
    pos[dot[i].second + 1]--;
    ocur[dot[i].first].push_back(i);
    ocur[dot[i].second + 1].push_back(-i);
  }
  for (long long i = 1; i < N; i++) pos[i] += pos[i - 1];
}
void Solve() {
  long long cur = 0;
  for (long long i = 0; i < N; i++) {
    cur += del[i];
    for (long long v : ocur[i])
      if (v > 0)
        heap.insert({dot[v].second, v});
      else {
        auto it = heap.find({dot[-v].second, -v});
        if (it != heap.end()) heap.erase(it);
      }
    while (pos[i] - cur > k) {
      if (heap.empty()) break;
      long long vt = heap.rbegin()->second;
      heap.erase(prev(heap.end()));
      cur++;
      ans.push_back(vt);
      del[dot[vt].second + 1]--;
    }
  }
  cout << ans.size() << endl;
  for (long long i : ans) cout << i << ' ';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  In();
  Solve();
}
