#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, n, k, x, y;
  cin >> n >> k;
  vector<pair<pair<int, int>, int>> a;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    a.push_back({{x, y}, i + 1});
  }
  sort(a.begin(), a.end());
  vector<int> ans;
  set<pair<int, int>> second;
  int ind = 0;
  for (i = 1; i < 200005; i++) {
    while (ind < n and a[ind].first.first <= i) {
      second.insert({a[ind].first.second, a[ind].second});
      ind++;
    }
    while (!second.empty() and (second.begin()->first < i)) {
      second.erase(second.begin());
    }
    while (second.size() > k) {
      ans.push_back(prev(second.end())->second);
      second.erase(prev(second.end()));
    }
  }
  cout << ans.size();
  cout << "\n";
  for (auto i : ans) cout << i << " ";
  return 0;
}
