#include <bits/stdc++.h>
using namespace std;
// #define int long long
const int N = 2e5 + 5, MX = 2e5;
struct node {
int mx, lazy;
} t[N << 2];
struct node1{
int mx, pos;
} t1[N << 2];
int n, k, ss[N];
map<pair<int, int>, vector<int>> mp;
vector<int> val[N];
void down(int p) {
if (!t[p].lazy) return;
t[p << 1].lazy += t[p].lazy;
t[p << 1 | 1].lazy += t[p].lazy;
t[p << 1].mx += t[p].lazy;
t[p << 1 | 1].mx += t[p].lazy;
t[p].lazy = 0;
}
void upd(int p, int l, int r, int u, int v) {
if (l > v || r < u) return;
if (u <= l && r <= v) {
t[p].lazy--;
t[p].mx--;
return;
}
down(p);
int mid = (l + r) / 2;
upd(p << 1, l, mid, u, v);
upd(p << 1 | 1, mid + 1, r, u, v);
t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx);
}
int get(int p, int l, int r) {
if (l == r) return (t[p].mx > k ? l : -1);
int mid = (l + r) / 2;
down(p);
if (t[p << 1].mx > k) return get(p << 1, l, mid);
return get(p << 1 | 1, mid + 1, r);
}
void init(int p, int l, int r) {
if (l == r) {
t1[p].mx = (val[l].size() ? val[l].back() : 0);
t1[p].pos = l;
return;
}
int mid = (l + r) / 2;
init(p << 1, l, mid);
init(p << 1 | 1, mid + 1, r);
t1[p].mx = max(t1[p << 1].mx, t1[p << 1 | 1].mx);
t1[p].pos = (t1[p << 1].mx > t1[p << 1 | 1].mx ? t1[p << 1].pos : t1[p << 1 | 1].pos);
}
void ers(int p, int l, int r, int pos) {
if (l == r) {
if (val[l].size()) val[l].pop_back();
if (val[l].size()) t1[p].mx = val[l].back();
else t1[p].mx = 0;
t1[p].pos = l;
return;
}
int mid = (l + r) / 2;
if (pos <= mid) ers(p << 1, l, mid, pos);
else ers(p << 1 | 1, mid + 1, r, pos);
t1[p].mx = max(t1[p << 1].mx, t1[p << 1 | 1].mx);
t1[p].pos = (t1[p << 1].mx > t1[p << 1 | 1].mx ? t1[p << 1].pos : t1[p << 1 | 1].pos);
}
pair<int, int> get1(int p, int l, int r, int u) {
if (r <= u) return {t1[p].pos, t1[p].mx};
if (l > u) return pair<int, int>{-1, -1};
int mid = (l + r) / 2;
pair<int, int> p1 = get1(p << 1, l, mid, u);
pair<int, int> p2 = get1(p << 1 | 1, mid + 1, r, u);
return (p1.second > p2.second ? p1 : p2);
}
void init1(int p, int l, int r) {
if (l == r) {
t[p].mx = ss[l];
return;
}
int mid = (l + r) / 2;
init1(p << 1, l, mid);
init1(p << 1 | 1, mid + 1, r);
t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx);
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
static int fi, se;
cin >> fi >> se;
val[fi].emplace_back(se);
mp[{fi,se}].emplace_back(i);
ss[fi]++, ss[se+1]--;
}
for (int i = 1; i < N; ++i) {
ss[i] += ss[i-1];
sort(val[i].begin(), val[i].end());
}
init1(1, 1, MX);
init(1, 1, MX);
int p = get(1, 1, MX);
int ans = 0;
vector<int> vt;
while(p != -1) {
pair<int, int> del = get1(1, 1, MX, p);
int poss = mp[{del.first, del.second}].back();
mp[{del.first, del.second}].pop_back();
ans++; vt.emplace_back(poss);
upd(1, 1, MX, del.first, del.second);
ers(1, 1, MX, del.first);
p = get(1, 1, MX);
}
cout << ans << '\n';
for (int x : vt) cout << x << ' ';
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int tc = 1; // cin >> tc;
while(tc--) solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Ci8vICNkZWZpbmUgaW50IGxvbmcgbG9uZwpjb25zdCBpbnQgTiA9IDJlNSArIDUsIE1YID0gMmU1OwoKc3RydWN0IG5vZGUgewogIGludCBteCwgbGF6eTsKfSB0W04gPDwgMl07CgpzdHJ1Y3Qgbm9kZTF7CiAgaW50IG14LCBwb3M7Cn0gdDFbTiA8PCAyXTsKCmludCBuLCBrLCBzc1tOXTsKbWFwPHBhaXI8aW50LCBpbnQ+LC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