#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 gen(time(0));
int n, m, x;
vector<int> ans;
map<int, vector<pair<int, int>>> arr;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    arr[x].push_back({y, i});
  }
  int now = 0;
  set<pair<int, int>> s;
  for (auto &i : arr) {
    while (!s.empty() && s.begin()->first < i.first) s.erase(s.begin());
    for (auto j : i.second) s.insert(j);
    while (s.size() > m) {
      ans.push_back(prev(s.end())->second);
      s.erase(prev(s.end()));
    }
  }
  cout << ans.size() << '\n';
  for (auto i : ans) cout << i << " ";
  cout << '\n';
  return 0;
}
