#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long m) {
  long long r = 1;
  a %= m;
  for (; b; b >>= 1) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
  }
  return r;
}
const int inf = 0x7fffffff;
const int maxn = 2e5 + 10;
vector<pair<int, int> > g[maxn];
vector<int> ans;
set<pair<int, int> > s;
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int l, r;
    cin >> l >> r;
    g[l].push_back(pair<int, int>(r, i));
  }
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < (int)(g[i]).size(); j++) s.insert(g[i][j]);
    while ((int)(s).size() > k) {
      set<pair<int, int> >::iterator it = s.end();
      it--;
      ans.push_back(it->second);
      s.erase(it);
    }
    while (!s.empty() && (s.begin()->first) <= i) s.erase(s.begin());
  }
  cout << (int)(ans).size() << endl;
  for (int i = 0; i < (int)(ans).size(); i++) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
