#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6 + 10;
int sum[Maxn << 2], tag[Maxn << 2];
struct Point {
  int l, r;
  int idx;
} point[Maxn];
struct Node {
  int l, r;
  int mid() { return (l + r) >> 1; }
} node[Maxn << 2];
void buildtree(int l, int r, int rt) {
  node[rt].l = l;
  node[rt].r = r;
  sum[rt] = 0;
  tag[rt] = 0;
  if (l == r) {
    return;
  }
  int mi = node[rt].mid();
  buildtree(l, mi, rt << 1);
  buildtree(mi + 1, r, rt << 1 | 1);
}
void pushdown(int rt) {
  if (tag[rt]) {
    tag[rt << 1] += tag[rt];
    tag[rt << 1 | 1] += tag[rt];
    sum[rt << 1] += tag[rt];
    sum[rt << 1 | 1] += tag[rt];
    tag[rt] = 0;
  }
}
void pushup(int rt) { sum[rt] = max(sum[rt << 1], sum[rt << 1 | 1]); }
void updata(int l, int r, int rt) {
  if (node[rt].l == l && node[rt].r == r) {
    sum[rt] += 1;
    tag[rt] += 1;
    return;
  }
  pushdown(rt);
  int mi = node[rt].mid();
  if (r <= mi)
    updata(l, r, rt << 1);
  else if (l > mi)
    updata(l, r, rt << 1 | 1);
  else {
    updata(l, mi, rt << 1);
    updata(mi + 1, r, rt << 1 | 1);
  }
  pushup(rt);
}
int query(int l, int r, int rt) {
  if (node[rt].l == l && node[rt].r == r) {
    return sum[rt];
  }
  pushdown(rt);
  int mi = node[rt].mid();
  int ans = 0;
  if (r <= mi)
    ans = max(ans, query(l, r, rt << 1));
  else if (l > mi)
    ans = max(ans, query(l, r, rt << 1 | 1));
  else {
    ans = max(ans, query(l, mi, rt << 1));
    ans = max(ans, query(mi + 1, r, rt << 1 | 1));
  }
  return ans;
}
int ans1[Maxn];
bool cmp(Point a, Point b) { return a.r < b.r || a.r == b.r && a.l < b.l; }
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int mil = 0x3f3f3f3f, mar = -1;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &point[i].l, &point[i].r);
      mil = min(mil, point[i].l);
      mar = max(mar, point[i].r);
      point[i].idx = i + 1;
    }
    sort(point, point + n, cmp);
    buildtree(1, 200010, 1);
    int total = 0;
    for (int i = 0; i < n; i++) {
      if (query(point[i].l, point[i].r, 1) < m) {
        updata(point[i].l, point[i].r, 1);
      } else
        ans1[total++] = point[i].idx;
    }
    printf("%d\n", total);
    for (int i = 0; i < total; i++) {
      if (i == total - 1)
        printf("%d\n", ans1[i]);
      else
        printf("%d ", ans1[i]);
    }
  }
  return 0;
}
