#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long inf = 1LL << 30;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int N = 200200;
set<pair<int, int>, greater<pair<int, int>>> s;
vector<pair<int, int>> vl[N], vr[N];
map<int, int> L, R;
vector<int> ans;
set<int> ren;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    vl[l].push_back({r, i});
    vr[r].push_back({r, i});
    ren.insert(l);
    ren.insert(r);
    L[l]++;
    R[r]++;
  }
  int cnt = 0;
  for (auto x : ren) {
    cnt += L[x];
    for (auto p : vl[x]) s.insert(p);
    while (cnt > k) {
      pair<int, int> p = *s.begin();
      s.erase(s.begin());
      ans.push_back(p.second);
      R[p.first]--;
      cnt--;
    }
    cnt -= R[x];
    for (auto p : vr[x])
      if (s.count(p)) s.erase(p);
  }
  printf("%d\n", ans.size());
  for (auto x : ans) printf("%d ", x);
}
