#include <bits/stdc++.h>
#pragma GCC optimize("03")
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
inline int read() {
  int ans = 0;
  bool f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = getchar();
  return f ? ans : -ans;
}
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > v[200010];
int n, k;
int cnt[200010];
vector<int> ans;
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int l, r;
    cin >> l >> r;
    v[l].push_back(make_pair(r, i));
    cnt[r]++;
  }
  int pos = 0;
  for (int i = 1; i < 200010; i++) {
    pos += v[i].size();
    for (int j = 0; j < v[i].size(); j++) pq.push(v[i][j]);
    while (pos > k) {
      pair<int, int> x = pq.top();
      pq.pop();
      ans.push_back(x.second);
      cnt[x.first]--;
      pos--;
    }
    pos -= cnt[i];
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
