#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k;
vector<pair<int, int>> ri[N];
int pref[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ri[l].push_back({r, i});
    pref[l]++;
    pref[r + 1]--;
  }
  int sum = 0;
  vector<int> ans;
  priority_queue<pair<int, int>> pq;
  for (int i = 1; i <= N - 5; i++) {
    sum += pref[i];
    for (auto it : ri[i]) {
      pq.push(it);
    }
    while (sum > k) {
      sum--;
      pref[pq.top().first + 1]++;
      ans.push_back(pq.top().second + 1);
      pq.pop();
    }
  }
  cout << ans.size() << '\n';
  sort(ans.begin(), ans.end());
  for (auto it : ans) {
    cout << it << ' ';
  }
  cout << '\n';
  return 0;
}
