#include <bits/stdc++.h>
using namespace std;
int n, k, a[200100], last = 1;
vector<int> ans;
vector<pair<int, int> > v[200100];
multiset<pair<int, int> > ms;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    a[L]++;
    a[R + 1]--;
    v[L].push_back({R, i + 1});
  }
  for (int i = 1; i <= 2e5; i++) {
    a[i] += a[i - 1];
    for (pair<int, int> j : v[i]) ms.insert(j);
    while (a[i] > k) {
      pair<int, int> p = *(--ms.end());
      ms.erase(--ms.end());
      ans.push_back(p.second);
      a[i]--;
      a[p.first + 1]++;
    }
  }
  cout << ans.size() << endl;
  for (int x : ans) cout << x << " ";
  return 0;
}
