#include <bits/stdc++.h>
using namespace std;
int vis[200005];
pair<int, int> seg[200005];
vector<pair<int, pair<int, int> > > v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long m, n, i, j, t, x, y, w, k, l, r;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> l >> r;
    v.push_back({l, {i, 1}});
    v.push_back({r + 1, {i, -1}});
    seg[i].first = l;
    seg[i].second = r + 1;
  }
  sort(v.begin(), v.end());
  vector<int> ans;
  priority_queue<pair<int, int> > pq;
  int count = 0;
  for (i = 0; i < v.size();) {
    x = v[i].first;
    while (i < v.size() && x == v[i].first) {
      if (vis[v[i].second.first]) {
        i++;
        continue;
      }
      if (v[i].second.second == 1) {
        pq.push({seg[v[i].second.first].second, v[i].second.first});
      }
      count += v[i].second.second;
      i++;
    }
    if (count > k) {
      int rem = count - k;
      count = k;
      while (true) {
        if (vis[pq.top().second] == 1) {
          pq.pop();
          continue;
        }
        rem--;
        ans.push_back(pq.top().second);
        vis[pq.top().second] = 1;
        pq.pop();
        if (rem == 0) break;
      }
    }
  }
  cout << ans.size() << "\n";
  sort(ans.begin(), ans.end());
  for (auto x : ans) {
    cout << x + 1 << " ";
  }
  cout << "\n";
  return 0;
}
