#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using Pa = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vec<int> L(N), R(N);
  int ma = 2e5;
  vvec<Pa<int, int>> list(ma);
  for (int i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
    L[i]--;
    R[i]--;
    list[L[i]].push_back({R[i], i});
  }
  vec<int> ans;
  set<Pa<int, int>> s;
  for (int i = 0; i < ma; i++) {
    for (auto p : list[i]) s.insert(p);
    while (s.size() > K) {
      auto p = *s.rbegin();
      ans.push_back(p.second);
      s.erase(p);
    }
    while (!s.empty()) {
      auto p = *s.begin();
      if (p.first == i) {
        s.erase(p);
      } else
        break;
    }
  }
  cout << ans.size() << "\n";
  for (auto& x : ans) cout << x + 1 << " ";
  cout << "\n";
}
