#include <bits/stdc++.h>
using namespace std;
const int Z = (int)3e3 + 228;
const int N = (int)3e5 + 228;
const int INF = (int)1e9 + 228;
const int MOD = (int)1e9 + 7;
const long long kek = 1000000000000000000;
const int lim = 37;
vector<pair<int, int> > v[N];
int l[N], r[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    v[l[i]].push_back({r[i], i});
  }
  multiset<pair<int, int> > mn;
  vector<int> ans;
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < v[i].size(); j++)
      mn.insert({v[i][j].first, v[i][j].second});
    while (!mn.empty() && mn.begin()->first < i) mn.erase(mn.begin());
    while (mn.size() > k) {
      auto it = *--mn.end();
      ans.push_back(it.second);
      mn.erase(--mn.end());
    }
  }
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  for (int i : ans) cout << i << ' ';
  return 0;
}
