#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  set<tuple<int, bool, int>> queue;
  vector<pair<int, int>> planks(N);
  int a, b;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    planks[i] = {a, b};
    queue.insert({a, 0, i});
    queue.insert({b, 1, i});
  }
  set<int> remove;
  set<pair<int, int>> current;
  int loc, num;
  bool type;
  while (!queue.empty()) {
    tie(loc, type, num) = *queue.begin();
    queue.erase(queue.begin());
    if (type == 0) {
      current.insert({loc, num});
    } else if (current.find({planks[num].first, num}) != current.end()) {
      current.erase(current.find({planks[num].first, num}));
    }
    if (current.size() > K) {
      set<pair<int, int>>::iterator best = current.begin();
      for (auto it = current.begin(); it != current.end(); ++it) {
        if (planks[(*it).second].second > planks[(*best).second].second) {
          best = it;
        }
      }
      remove.insert((*best).second);
      current.erase(best);
    }
  }
  cout << remove.size() << '\n';
  for (auto ele : remove) {
    cout << ele + 1 << ' ';
  }
  return 0;
}
