#include <bits/stdc++.h>
using namespace std;
int a[400005] = {0};
int tree[4 * 400005] = {0};
int lazy[4 * 400005] = {0};
vector<pair<int, int> > v[100005];
vector<int> g[100005];
int ans[100005] = {0};
void build(int node, int l, int r) {
  if (l == r) {
    tree[node] = 0;
    lazy[node] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * node, l, mid);
  build(2 * node + 1, mid + 1, r);
  tree[node] = min(tree[2 * node], tree[2 * node + 1]);
}
void add(int node, int start, int end) {
  tree[node] += lazy[node];
  if (start != end) {
    lazy[2 * node] += lazy[node];
    lazy[2 * node + 1] += lazy[node];
  }
  lazy[node] = 0;
}
int n;
void update(int node, int start, int end, int l, int r, int x) {
  if (lazy[node] != 0) {
    add(node, start, end);
  }
  if (l > end || r < start) return;
  if (start >= l && end <= r) {
    lazy[node] += x;
    if (lazy[node] != 0) {
      add(node, start, end);
    }
  } else {
    int mid = (start + end) / 2;
    update(2 * node, start, mid, l, r, x);
    update(2 * node + 1, mid + 1, end, l, r, x);
    tree[node] = min(tree[2 * node], tree[2 * node + 1]);
  }
}
int query(int node, int start, int end, int l, int r) {
  if (lazy[node] != 0) {
    add(node, start, end);
  }
  if (l > end || r < start) return 1e9;
  if (start >= l && end <= r) {
    return tree[node];
  } else {
    int mid = (start + end) / 2;
    int p1 = query(2 * node, start, mid, l, r);
    int p2 = query(2 * node + 1, mid + 1, end, l, r);
    return min(p1, p2);
  }
}
int main() {
  int q, k;
  int l[200005], r[200005];
  cin >> q >> k;
  vector<pair<int, int> > s[200005];
  for (int i = 1; i <= q; i++) {
    cin >> l[i] >> r[i];
    update(1, 1, 200000, l[i], r[i], 1);
    s[l[i]].push_back(make_pair(r[i], i));
  }
  for (int i = 1; i <= 200000; i++) {
    sort(s[i].begin(), s[i].end());
  }
  set<pair<int, int> > ss;
  vector<int> v;
  for (int i = 1; i <= 200000; i++) {
    int x = query(1, 1, 200000, i, i);
    if (x > k) {
      int p = x - k;
      if (ss.size() == 0) {
        int y = s[i].size() - 1;
        for (int j = 1; j <= x - k; j++) {
          update(1, 1, 200000, i, s[i][y].first, -1);
          v.push_back(s[i][y].second);
          y--;
        }
        for (int j = y; j >= 0; j--) {
          ss.insert(make_pair(-1 * s[i][j].first, s[i][j].second));
        }
      } else {
        int y = s[i].size() - 1;
        while (p > 0) {
          p--;
          auto it = ss.begin();
          if (y >= 0 && it != ss.end() && s[i][y].first >= (-1 * it->first)) {
            update(1, 1, 200000, i, s[i][y].first, -1);
            v.push_back(s[i][y].second);
            y--;
          } else if (y >= 0 && it != ss.end() &&
                     s[i][y].first < (-1 * it->first)) {
            update(1, 1, 200000, i, -1 * it->first, -1);
            v.push_back(it->second);
            ss.erase(it);
          } else if (y >= 0) {
            update(1, 1, 200000, i, s[i][y].first, -1);
            v.push_back(s[i][y].second);
            y--;
          } else {
            update(1, 1, 200000, i, -1 * it->first, -1);
            v.push_back(it->second);
            ss.erase(it);
          }
        }
        for (int j = y; j >= 0; j--) {
          ss.insert(make_pair(-1 * s[i][j].first, s[i][j].second));
        }
      }
    } else {
      int y = s[i].size() - 1;
      for (int j = y; j >= 0; j--) {
        ss.insert(make_pair(-1 * s[i][j].first, s[i][j].second));
      }
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
