#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> e;
  UF(int n) : e(n, -1) {}
  bool same_set(int a, int b) { return find(a) == find(b); }
  int size(int x) { return -e[find(x)]; }
  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
  void join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b];
    e[b] = a;
  }
};
long long int p = 1000000007;
long long int power(long long int a, long long int b) {
  if (!b) return 1;
  long long int ans = power(a, b / 2);
  ans = (ans * ans) % p;
  if (b % 2) ans = (ans * a) % p;
  return ans;
}
bool compare(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first < b.first)
    return true;
  else if (a.first.first == b.first.first) {
    if (a.first.second > b.first.second)
      return true;
    else
      return false;
  } else
    return false;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n, k;
  cin >> n >> k;
  vector<pair<pair<int, int>, int>> temp;
  int a, b, c, d, e, f;
  for (int i = 0; i < (n); ++i) {
    cin >> a >> b;
    temp.push_back({{a, b}, i});
  }
  sort(temp.begin(), temp.end());
  int dp[200009];
  memset(dp, 0, sizeof(dp));
  int i = 0, j = 0;
  vector<int> ans;
  multiset<pair<int, int>> temp1;
  while (i < n && j <= 200000) {
    if (j < temp[i].first.first) {
      dp[j] += dp[j - 1];
      j++;
    } else {
      dp[j] += dp[j - 1];
      while (temp[i].first.first == j) {
        if (dp[j] < k) {
          dp[j]++;
          dp[temp[i].first.second + 1]--;
          temp1.insert({-temp[i].first.second, temp[i].second});
          i++;
        } else {
          dp[temp[i].first.second + 1]--;
          auto it1 = temp1.begin();
          temp1.insert({-temp[i].first.second, temp[i].second});
          auto it = temp1.begin();
          ans.push_back((*it).second);
          b = (*it).first;
          dp[-b + 1]++;
          temp1.erase(it);
          i++;
        }
      }
      j++;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (ans.size()); ++i) cout << ans[i] + 1 << " ";
}
