#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 45;
pair<int, int> a[N];
multiset<pair<int, int> > s;
vector<pair<int, int> > ev;
vector<int> rem;
bool obrisan[N];
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) {
    return a.second > b.second;
  }
  return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second;
    ev.push_back(pair<int, int>(a[i].first, i));
    ev.push_back(pair<int, int>(a[i].second, -i));
  }
  sort(ev.begin(), ev.end(), cmp);
  for (auto f : ev) {
    if (obrisan[abs(f.second)]) {
      continue;
    }
    if (f.second < 0) {
      while (s.size() > k) {
        pair<int, int> e = *s.rbegin();
        rem.push_back(e.second);
        obrisan[e.second] = 1;
        s.erase(s.find(e));
      }
      s.erase(s.find(pair<int, int>(f.first, -f.second)));
    } else {
      int id = f.second;
      s.insert(pair<int, int>(a[id].second, id));
    }
  }
  cout << rem.size() << endl;
  for (auto f : rem) {
    cout << f << " ";
  }
  cout << endl;
}
