#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
long long N, K, seg[maxn << 2], lazy[maxn << 2];
struct Node {
  long long l, r, id;
  friend bool operator<(const Node& a, const Node& b) { return a.r < b.r; }
  friend bool operator>(const Node& a, const Node& b) { return a.r > b.r; }
};
inline long long cmp(const Node& a, const Node& b) { return a.l < b.l; }
inline void pushdown(long long cur) {
  if (lazy[cur]) {
    seg[(cur << 1)] += lazy[cur];
    seg[(cur << 1 | 1)] += lazy[cur];
    lazy[(cur << 1)] += lazy[cur];
    lazy[(cur << 1 | 1)] += lazy[cur];
    lazy[cur] = 0;
  }
}
inline void pushup(long long cur) {
  seg[cur] = max(seg[(cur << 1)], seg[(cur << 1 | 1)]);
}
inline void update(long long l, long long r, long long L, long long R,
                   long long cur, long long val) {
  if (l >= L && r <= R) {
    seg[cur] += val;
    lazy[cur] += val;
    return;
  }
  pushdown(cur);
  if (((l + r) >> 1) >= L) {
    update(l, ((l + r) >> 1), L, R, (cur << 1), val);
  }
  if (((l + r) >> 1) < R) {
    update(((l + r) >> 1) + 1, r, L, R, (cur << 1 | 1), val);
  }
  pushup(cur);
}
inline long long query(long long l, long long r, long long L, long long R,
                       long long cur) {
  if (l >= L && r <= R) {
    return seg[cur];
  }
  pushdown(cur);
  long long ans = 0;
  if (((l + r) >> 1) >= L) {
    ans = query(l, ((l + r) >> 1), L, R, (cur << 1));
  }
  if (((l + r) >> 1) < R) {
    ans = max(ans, query(((l + r) >> 1) + 1, r, L, R, (cur << 1 | 1)));
  }
  return ans;
}
vector<Node> v;
vector<long long> res;
const long long RR = 2e5;
signed main() {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  for (register long long i = 1; i <= N; ++i) {
    Node nN;
    cin >> nN.l >> nN.r;
    nN.id = i;
    v.push_back(nN);
  }
  priority_queue<Node> q;
  sort(v.begin(), v.end(), cmp);
  long long sz = v.size(), cnt = 0;
  for (register long long i = 0; i < sz; ++i) {
    update(1, RR, v[i].l, v[i].r, 1, 1);
    long long mx = seg[1];
    if (mx > K) {
      Node top = q.top();
      if (top.r > v[i].r) {
        q.pop();
        q.push(v[i]);
        res.push_back(top.id);
      } else {
        top = v[i];
        res.push_back(top.id);
      }
      update(1, RR, top.l, top.r, 1, -1);
      ++cnt;
    } else {
      q.push(v[i]);
    }
  }
  cout << cnt << endl;
  for (auto&& i : res) {
    cout << i << " ";
  }
  return 0;
}
