#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T re() {
  T N = 0;
  char c = getchar();
  bool neg = 0;
  for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
  for (; c >= '0' && c <= '9'; c = getchar()) N = (N << 3) + (N << 1) + c - '0';
  return neg ? -N : N;
}
const int MX = 2e5;
int n, k;
int prf[MX + 5], l[MX + 5], r[MX + 5];
struct seg {
  int l, r, i;
  seg(int l = 0, int r = 0, int i = 0) : l(l), r(r), i(i) {}
  bool operator<(const seg &R) const {
    return r == R.r ? l != R.l ? l < R.l : i < R.i : r > R.r;
  }
};
set<seg> active;
set<seg>::iterator POS;
vector<int> removed;
vector<int> at[MX + 5];
int main() {
  n = re<int>();
  k = re<int>();
  for (int i = 1; i <= n; i++) {
    l[i] = re<int>();
    r[i] = re<int>();
    prf[l[i]]++;
    prf[r[i] + 1]--;
    at[l[i]].push_back(i);
    at[r[i] + 1].push_back(-i);
  }
  for (int i = 1; i <= MX; i++) {
    prf[i] += prf[i - 1];
    sort(at[i].begin(), at[i].end());
  }
  for (int i = 1; i <= MX; i++) {
    for (int j : at[i]) {
      if (j < 0) {
        POS = active.find(seg(l[-j], r[-j], -j));
        if (POS != active.end()) {
          active.erase(POS);
        }
      } else {
        active.insert(seg(l[j], r[j], j));
      }
    }
    while (active.size() > k) {
      seg u = *active.begin();
      removed.push_back(u.i);
      active.erase(active.begin());
    }
  }
  printf("%lu\n", removed.size());
  for (int i = 0; i < removed.size(); i++)
    printf("%d%c", removed[i], " \n"[i + 1 == removed.size()]);
  return 0;
}
