#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, k, l, r, freq[MAXN], BP[MAXN], bSeg[MAXN], cnt, ri[MAXN];
set<pair<int, int> > st;
vector<pair<int, pair<int, int> > > x[MAXN];
vector<pair<int, int> > seg;
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    seg.push_back(make_pair(l, r));
    freq[l]++, freq[r + 1]--;
    ri[r]++;
  }
  for (int i = 1; i < MAXN; i++) {
    freq[i] += freq[i - 1];
    if (freq[i] > k) BP[i] = 1;
  }
  for (int i = 1; i < MAXN; i++) BP[i] += BP[i - 1];
  for (int i = 0; i < n; i++) {
    bSeg[i] = BP[seg[i].second] - BP[seg[i].first - 1];
    x[seg[i].first].push_back(
        make_pair(bSeg[i], make_pair(seg[i].second, i + 1)));
  }
  int ans = 0;
  vector<int> idxx;
  for (int i = 1; i < MAXN; i++) {
    for (int j = 0; j < x[i].size(); j++) {
      cnt++;
      st.insert(make_pair(x[i][j].second.first, x[i][j].second.second));
    }
    cnt -= ri[i - 1];
    while (st.size() > k && cnt > k && freq[i] > k) {
      pair<int, int> temp = *st.rbegin();
      if (temp.first < i) {
        st.erase(temp);
      } else {
        cnt--;
        ans++;
        idxx.push_back(temp.second);
        ri[temp.first]--;
        st.erase(temp);
        freq[i]--;
      }
    }
  }
  cout << ans << endl;
  for (int i = 0; i < idxx.size(); i++) {
    cout << idxx[i] << ' ';
  }
  cout << endl;
  return 0;
}
