#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long powmd(long long a, long long b) {
  a = a % md;
  long long ret = 1;
  for (; b; b >>= 1) {
    if (b & 1) {
      ret = ret * b % md;
    }
    b = b * b % md;
  }
  return ret;
}
const int MAX = 200110;
int pre[MAX], n, k;
pair<int, int> v[MAX];
vector<vector<int> > io(MAX);
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
    pre[v[i].first]++;
    pre[v[i].second + 1]--;
    io[v[i].first].push_back(i + 1);
    io[v[i].second + 1].push_back(-i - 1);
  }
  for (int i = 1; i < MAX; ++i) {
    pre[i] += pre[i - 1];
  }
  vector<int> ans(MAX), sub(MAX);
  set<pair<int, int> > segments;
  int currentRemoved = 0;
  for (int i = 0; i < MAX; ++i) {
    currentRemoved += sub[i];
    for (int j = 0; j < io[i].size(); ++j) {
      if (io[i][j] > 0) {
        segments.insert(make_pair(v[io[i][j] - 1].second, io[i][j] - 1));
      } else {
        set<pair<int, int> >::iterator it =
            segments.find(make_pair(v[-io[i][j] - 1].second, -io[i][j] - 1));
        if (it != segments.end()) segments.erase(it);
      }
    }
    while (pre[i] - currentRemoved > k) {
      currentRemoved++;
      int maximalPositionReach = segments.rbegin()->second;
      segments.erase(prev(segments.end()));
      ans[maximalPositionReach] = 1;
      sub[v[maximalPositionReach].second + 1]--;
    }
  }
  int cnt = 0;
  for (int i = 0; i < ans.size(); ++i)
    if (ans[i]) cnt++;
  cout << cnt << '\n';
  for (int i = 0; i < ans.size(); ++i) {
    if (ans[i]) cout << i + 1 << ' ';
  }
  cout << '\n';
}
