#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
int L[N], R[N];
vector<int> In[N], Out[N];
set<pair<pair<int, int>, int> > st;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", L + i, R + i);
    In[L[i]].push_back(i);
    Out[R[i]].push_back(i);
  }
  vector<int> Ans;
  for (int x = 1; x < N; x++) {
    for (int i : In[x]) {
      st.insert(pair<pair<int, int>, int>(pair<int, int>(R[i], L[i]), i));
    }
    while (st.size() > k) {
      auto P = *st.rbegin();
      Ans.push_back(P.second);
      st.erase(P);
    }
    for (int i : Out[x]) {
      st.erase(pair<pair<int, int>, int>(pair<int, int>(R[i], L[i]), i));
    }
  }
  sort(Ans.begin(), Ans.end());
  cout << Ans.size() << endl;
  for (int x : Ans) printf("%d ", x);
  puts("");
}
