#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int x) { return x % 1000000007; }
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
class compare {
 public:
  bool operator()(
      const pair<pair<long long int, long long int>, long long int> &a,
      const pair<pair<long long int, long long int>, long long int> &b) {
    if (a.first.first != b.first.first) a.first.first > b.first.first;
    return a.first.second < b.first.second;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  vector<pair<pair<long long int, long long int>, long long int> > v;
  vector<long long int> ref(200020);
  for (long long int i = 0; i < n; ++i) {
    long long int a, b;
    cin >> a >> b;
    v.push_back({{a, b}, i + 1});
    ref[a]++;
    ref[b + 1]--;
  }
  for (long long int i = 1; i < ref.size(); ++i) ref[i] += ref[i - 1];
  sort(v.begin(), v.end());
  priority_queue<
      pair<pair<long long int, long long int>, long long int>,
      vector<pair<pair<long long int, long long int>, long long int> >, compare>
      pq;
  long long int j = 0;
  vector<long long int> ans;
  vector<long long int> pref(200020);
  for (long long int i = 1; i < ref.size(); ++i) {
    pref[i] += pref[i - 1];
    ref[i] += pref[i];
    while (j < v.size()) {
      if (v[j].first.first > i) break;
      pq.push(v[j]);
      ++j;
    }
    while (!pq.empty()) {
      if (pq.top().first.second >= i) break;
      pq.pop();
    }
    while (ref[i] > k) {
      if (pq.top().first.first > i || pq.top().first.second < i) break;
      --pref[i];
      --ref[i];
      pref[pq.top().first.second + 1]++;
      ans.push_back(pq.top().second);
      pq.pop();
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
  ;
}
