#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<vector<long long int>> v;
  vector<pair<long long int, long long int>> seg;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    seg.push_back({a, b});
    v.push_back({a, 0, i});
    v.push_back({b, 1, i});
  }
  set<long long int> ans;
  set<pair<long long int, long long int>> cur;
  sort(v.begin(), v.end());
  vector<long long int> removed(2 * n + 1, 0);
  for (auto ar : v) {
    if (ar[1] == 0) {
      cur.insert({seg[ar[2]].second, ar[2]});
      if ((long long int)cur.size() > k) {
        auto j = cur.end();
        j--;
        removed[j->second] = 1;
        ans.insert(j->second);
        cur.erase(j);
      }
    } else {
      if (removed[ar[2]]) continue;
      cur.erase({ar[0], ar[2]});
    }
  }
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i + 1 << " ";
  return 0;
}
