The only difference between easy and hard versions is constraints.

You are given $n$ segments on the coordinate axis $OX$. Segments can intersect, lie inside each other and even coincide. The $i$-th segment is $[l_i; r_i]$ ($l_i \le r_i$) and it covers all integer points $j$ such that $l_i \le j \le r_i$.

The integer point is called bad if it is covered by strictly more than $k$ segments.

Your task is to remove the minimum number of segments so that there are no bad points at all.


-----Input-----

The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 200$) — the number of segments and the maximum number of segments by which each integer point can be covered.

The next $n$ lines contain segments. The $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le 200$) — the endpoints of the $i$-th segment.


-----Output-----

In the first line print one integer $m$ ($0 \le m \le n$) — the minimum number of segments you need to remove so that there are no bad points.

In the second line print $m$ distinct integers $p_1, p_2, \dots, p_m$ ($1 \le p_i \le n$) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.


-----Examples-----
Input
7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9

Output
3
1 4 7 

Input
5 1
29 30
30 30
29 29
28 30
30 30

Output
3
1 2 4 

Input
6 1
2 3
3 3
2 3
2 2
2 3
2 3

Output
4
1 3 5 6

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms


Solutions:
import sys
from collections import defaultdict
import heapq
(n, k) = map(int, sys.stdin.readline().split())
clouds = []
points = [0 for _ in range(201)]
for _ in range(n):
	(u, v) = map(int, sys.stdin.readline().split())
	clouds.append([u, v, _])
	for i in range(u, v + 1):
		points[i] += 1
clouds.sort()
(ans, i) = (0, 0)
heap = []
heapq.heapify(heap)
l = []
while i < n:
	start = clouds[i][0]
	while i < n:
		if clouds[i][0] == start:
			heapq.heappush(heap, [-clouds[i][1], clouds[i][2] + 1])
			i += 1
		else:
			break
	while points[start] > k:
		(right, ind) = heapq.heappop(heap)
		right = abs(right)
		l.append(ind)
		for j in range(start, right + 1):
			points[j] -= 1
		ans += 1
print(ans)
print(*l)


(n, k) = list(map(int, input().split()))
l = [0] * n
r = [0] * n
events = [(0, 0)] * 2 * n
for i in range(n):
	(l[i], r[i]) = list(map(int, input().split()))
	events[2 * i] = (l[i], 0, i)
	events[2 * i + 1] = (r[i], 1, i)
events.sort()
import heapq as h
s = []
ans = []
for e in events:
	(x, t, id) = e
	if t == 0:
		h.heappush(s, (-r[id], l[id], id))
	else:
		temp = []
		while s:
			x = h.heappop(s)
			if x == (-r[id], l[id], id):
				break
			temp.append(x)
		for x in temp:
			h.heappush(s, x)
	while len(s) > k:
		x = h.heappop(s)
		ans.append(x[2])
print(len(ans))
print(*[x + 1 for x in ans])


(n, m) = map(int, input().split())
a = [[] for i in range(201)]
for i in range(n):
	(b, c) = map(int, input().split())
	a[b].append([c, i + 1])
l = 0
d = 0
stack = []
count = 0
for i in range(1, 201):
	a[i].sort()
	l = len(a[i])
	if l > m:
		d = l - m
		for j in range(d):
			stack.append(a[i][-1][1])
			a[i].pop(-1)
			count += 1
	while len(a[i]) > 0 and a[i][0][0] == i:
		a[i].pop(0)
	if len(a[i]) > 0:
		a[i + 1] = a[i + 1] + a[i]
print(count)
for i in range(count):
	print(stack[i], end=' ')


(n, k) = list(map(int, input().split()))
L = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	L[i].append(i)
L.sort(key=lambda x: x[1])

def c(x):
	for i in range(x[0], x[1] + 1):
		if T[i] >= k:
			return 0
	return 1
ans = 0
A = []
T = [0] * 203
i = 0
t = 0
while i < n:
	if c(L[i]) == 1:
		for j in range(L[i][0], L[i][1] + 1):
			T[j] += 1
		t = L[i][0]
	else:
		A.append(L[i][2] + 1)
		ans += 1
	i += 1
A.sort()
print(ans)
print(' '.join([str(i) for i in A]))


(n, k) = map(int, input().split())
N = 2 * 10 ** 5 + 1
pre = [0] * (N + 1)
seg = []
for i in range(n):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	seg.append([y, -x, i + 1])
	pre[x] += 1
	pre[y + 1] -= 1
seg.sort()
seg.reverse()
seg = [[-seg[i][1], seg[i][0], seg[i][2]] for i in range(len(seg))]
cov = [0] * (N + 1)
cov[0] = pre[0]
for i in range(1, N):
	cov[i] = cov[i - 1] + pre[i]
wyn = 0
ziomy = []
for i in range(N):
	p = 0
	while cov[i] > k:
		maksi = -1
		opti = -1
		mini = 100000000000
		for d in range(len(seg)):
			if seg[d][1] > maksi and seg[d][0] <= i:
				mini = 100000000000000
				maksi = seg[d][1]
				opti = d
			elif seg[d][1] == maksi and seg[d][0] < mini and (seg[d][0] <= i):
				mini = seg[d][0]
				opti = d
		pt = seg[opti][1]
		ziomy.append(seg[opti][2])
		pre[pt + 1] += 1
		pre[i] -= 1
		cov[i] -= 1
		p += 1
		seg.pop(opti)
	cov[i + 1] = cov[i] + pre[i + 1]
	wyn += p
print(wyn)
print(*ziomy)


def main():
	line = input().split()
	(n, k) = line
	n = int(n)
	k = int(k)
	arr = []
	covered = [0] * 202
	for i in range(n):
		(x, y) = input().split()
		x = int(x)
		y = int(y)
		arr.append([x, y])
		covered[x] += 1
		covered[y + 1] -= 1
	for i in range(201):
		if i - 1 >= 0:
			covered[i] += covered[i - 1]
	taken = [0] * n
	for i in range(201):
		while covered[i] > k:
			pos = -1
			best = 0
			for j in range(n):
				(x, y) = arr[j]
				if x <= i and i <= y and (taken[j] == 0) and (y > best):
					best = y
					pos = j
			assert pos != -1
			assert best != 0
			assert taken[pos] == 0
			taken[pos] = 1
			(x, y) = arr[pos]
			for q in range(x, y + 1):
				covered[q] -= 1
	ans = 0
	for i in taken:
		ans += i
	print(ans)
	if ans != 0:
		for (idx, i) in enumerate(taken):
			if i:
				print(idx + 1, end=' ')
		print()
main()


from operator import itemgetter
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
info = [list(map(int, input().split())) + [i] for i in range(n)]
info = sorted(info, key=itemgetter(1))
max_num = info[-1][1]
N = max_num
INF = 0
LV = (N - 1).bit_length()
N0 = 2 ** LV
data = [0] * (2 * N0)
lazy = [0] * (2 * N0)

def gindex(l, r):
	L = l + N0 >> 1
	R = r + N0 >> 1
	lc = 0 if l & 1 else (L & -L).bit_length()
	rc = 0 if r & 1 else (R & -R).bit_length()
	for i in range(LV):
		if rc <= i:
			yield R
		if L < R and lc <= i:
			yield L
		L >>= 1
		R >>= 1

def propagates(*ids):
	for i in reversed(ids):
		v = lazy[i - 1]
		if not v:
			continue
		lazy[2 * i - 1] += v
		lazy[2 * i] += v
		data[2 * i - 1] += v
		data[2 * i] += v
		lazy[i - 1] = 0

def update(l, r, x):
	(*ids,) = gindex(l, r)
	propagates(*ids)
	L = N0 + l
	R = N0 + r
	while L < R:
		if R & 1:
			R -= 1
			lazy[R - 1] += x
			data[R - 1] += x
		if L & 1:
			lazy[L - 1] += x
			data[L - 1] += x
			L += 1
		L >>= 1
		R >>= 1
	for i in ids:
		data[i - 1] = max(data[2 * i - 1], data[2 * i])

def query(l, r):
	propagates(*gindex(l, r))
	L = N0 + l
	R = N0 + r
	s = INF
	while L < R:
		if R & 1:
			R -= 1
			s = max(s, data[R - 1])
		if L & 1:
			s = max(s, data[L - 1])
			L += 1
		L >>= 1
		R >>= 1
	return s
ans = []
for i in range(n):
	(l, r, j) = info[i]
	r += 1
	if query(l, r) < m:
		update(l, r, 1)
	else:
		ans.append(j + 1)
print(len(ans))
print(*ans)


N = int(200000.0 + 3)
cum = [0] * N
(n, k) = map(int, input().split())
arr = [0] * n
for i in range(n):
	arr[i] = [[0, 0], i + 1]
	arr[i][0] = list(map(int, input().split()))
	cum[arr[i][0][0]] += 1
	cum[arr[i][0][1] + 1] -= 1
for i in range(1, N):
	cum[i] += cum[i - 1]
arr.sort()
st = set()
(res, j, prev) = ([], 0, 0)
rmv = [0] * N
for i in range(N):
	while j < n and arr[j][0][0] <= i:
		st.add((arr[j][0][1], arr[j][1]))
		j += 1
	prev -= rmv[i]
	while len(st) > 0 and cum[i] - prev > k:
		it = max(st)
		st.remove(it)
		res.append(it[1])
		rmv[it[0] + 1] += 1
		prev += 1
print(len(res))
print(*res)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def modInverse(b):
	g = gcd(b, mod)
	if g != 1:
		return -1
	else:
		return pow(b, mod - 2, mod)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def bucketsort(order, seq):
	buckets = [0] * (max(seq) + 1)
	for x in seq:
		buckets[x] += 1
	for i in range(len(buckets) - 1):
		buckets[i + 1] += buckets[i]
	new_order = [-1] * len(seq)
	for i in reversed(order):
		x = seq[i]
		idx = buckets[x] = buckets[x] - 1
		new_order[idx] = i
	return new_order

def ordersort(order, seq, reverse=False):
	bit = max(seq).bit_length() >> 1
	mask = (1 << bit) - 1
	order = bucketsort(order, [x & mask for x in seq])
	order = bucketsort(order, [x >> bit for x in seq])
	if reverse:
		order.reverse()
	return order

def long_ordersort(order, seq):
	order = ordersort(order, [int(i & 2147483647) for i in seq])
	return ordersort(order, [int(i >> 31) for i in seq])

def multikey_ordersort(order, *seqs, sort=ordersort):
	for i in reversed(range(len(seqs))):
		order = sort(order, seqs[i])
	return order

def solve(case):
	(n, k) = sep()
	seg = []
	a = []
	b = []
	x = [0] * 201
	for i in range(n):
		(l, r) = sep()
		seg.append((l, r))
		a.append(l)
		b.append(r)
		for j in range(l, r + 1):
			x[j] += 1
	order = multikey_ordersort(range(n), a, b)
	rem = set()
	for i in range(201):
		while x[i] > k:
			which = -1
			for j in order:
				if j in rem:
					continue
				if seg[j][0] <= i <= seg[j][1]:
					if which == -1:
						which = j
					elif seg[j][1] > seg[which][1]:
						which = j
			rem.add(which)
			for kk in range(seg[which][0], seg[which][1] + 1):
				x[kk] -= 1
	print(len(rem))
	for i in rem:
		print(i + 1, end=' ')
testcase(1)


(scount, badness) = [int(x) for x in input().split(' ')]
segments = []
length = 200
for i in range(scount):
	segments.append([int(x) - 1 for x in input().split(' ')])
	segments[-1].append(True)
array = [[] for x in range(length)]
badcheck = [0 for x in range(length)]
for i in range(scount):
	for k in range(segments[i][0], segments[i][1] + 1):
		array[k].append([segments[i][1], i])
		badcheck[k] += 1
for i in range(length):
	array[i].sort()
res = []
for i in range(length):
	while badcheck[i] > badness:
		fn = array[i].pop()
		while not segments[fn[1]][2] == True:
			fn = array[i].pop()
		segments[fn[1]][2] = False
		res.append(fn[1])
		for k in range(i, fn[0] + 1):
			badcheck[k] -= 1
res.sort()
printable = ''
for i in res:
	printable += str(i + 1) + ' '
print(len(res))
print(printable)


(n, k) = list(map(int, input().split()))
ar = []
for i in range(n):
	lolk = list(map(int, input().split()))
	ar.append([lolk[0], 0, lolk[1], i + 1])
	ar.append([lolk[1], 1, lolk[0], i + 1])
ar.sort()
queue = []
kek = 0
ans = 0
ans1 = []
ksjdfks = set()
for (time, type, end, lol) in ar:
	if lol not in ksjdfks:
		if type == 0:
			kek += 1
			queue.append([time, type, end, lol])
			queue.sort(key=lambda x: x[2])
			if kek > k:
				ans += 1
				ans1.append(queue[-1][3])
				ksjdfks.add(queue[-1][3])
				queue.pop()
				kek -= 1
		else:
			kek -= 1
			queue.pop(queue.index([end, 0, time, lol]))
print(ans)
print(*ans1)


def ass(x):
	s = []
	for i in open:
		s.append((G[i][1], i))
	s.sort(reverse=True)
	m = set()
	for i in range(x):
		m.add(s[i][1])
		R[s[i][0]].discard(s[i][1])
	return m
import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
L = dict()
R = dict()
Lx = set()
Rx = set()
G = []
for i in range(n):
	(a, b) = map(int, input().split())
	G.append((a, b))
	if a not in L:
		L[a] = set()
	if b not in R:
		R[b] = set()
	L[a].add(i)
	R[b].add(i)
	Lx.add(a)
	Rx.add(b)
Lx = list(Lx)
Rx = list(Rx)
Lx.sort()
Rx.sort()
l = 0
r = 0
open = set()
ans = set()
while l < len(Lx) and r < len(Rx):
	open |= L[Lx[l]]
	if len(open) > k:
		dx = len(open) - k
		delet = ass(dx)
		ans |= delet
		open -= delet
	l += 1
	if l == len(Lx):
		break
	while Rx[r] < Lx[l]:
		open -= R[Rx[r]]
		r += 1
ans = list(ans)
ans.sort()
for i in range(len(ans)):
	ans[i] += 1
print(len(ans))
print(*ans)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
S = [tuple(map(int, input().split())) + (i + 1,) for i in range(n)]
S.sort()
segtemp = 2 * 10 ** 5
seg_el = 1 << segtemp.bit_length()
SEG = [0] * (2 * seg_el)

def getvalue(n, seg_el):
	i = n + seg_el
	ANS = 0
	ANS += SEG[i]
	i >>= 1
	while i != 0:
		ANS += SEG[i]
		i >>= 1
	return ANS

def updates(l, r, x):
	L = l + seg_el
	R = r + seg_el
	while L < R:
		if L & 1:
			SEG[L] += x
			L += 1
		if R & 1:
			R -= 1
			SEG[R] += x
		L >>= 1
		R >>= 1
ind = 0
SH = []
ANS = []
import heapq
for point in range(segtemp):
	while ind < n and S[ind][0] <= point:
		(l, r, x) = S[ind]
		updates(l, r + 1, 1)
		ind += 1
		heapq.heappush(SH, (-r, l, x))
	while getvalue(point, seg_el) > k:
		(r, l, x) = heapq.heappop(SH)
		r = -r
		ANS.append(x)
		updates(l, r + 1, -1)
print(len(ANS))
print(*ANS)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
segs = {}
cord = [0 for s in range(200)]
dict1 = {}
ks = set([])
for s in range(n):
	(l, r) = map(int, input().split())
	l -= 1
	r -= 1
	if not (l, r) in segs:
		segs[l, r] = 1
		dict1[l, r] = [s + 1]
	else:
		segs[l, r] += 1
		dict1[l, r].append(s + 1)
	for b in range(l, r + 1):
		cord[b] += 1
		if cord[b] > k:
			ks.add(b)
ans = 0
indices = []
ks = list(ks)
ks.sort()
while len(ks) > 0:
	v0 = ks.pop()
	if cord[v0] > k:
		seg1 = []
		for b in segs:
			seg = b
			if seg[0] <= v0 <= seg[1]:
				a1 = []
				for s in range(seg[0], seg[1] + 1):
					if cord[s] > k:
						a1.append(s)
				for l in range(segs[b]):
					seg1.append((seg, a1))
		seg1.sort(key=lambda x: len(x[1]))
		while cord[v0] > k:
			v1 = seg1.pop()
			segs[v1[0]] -= 1
			if segs[v1[0]] == 0:
				segs.pop(v1[0])
			ans += 1
			indices.append(dict1[v1[0]].pop())
			for b in v1[1]:
				cord[b] -= 1
print(ans)
indices.sort()
print(*indices)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
fk = [-1] * 50

def fun(n, dp, u):
	print(fk)
	if n >= 0:
		if fk[n] != -1:
			return fk[n]
	dp = dp[:]
	if n >= 0 and check(dp, u, n) == True:
		fk[n] = True
		return True
	if n <= 0:
		return False
	dp[n] -= 1
	dp[n - 1] += 1
	if n >= 2:
		dp[n - 2] += 1
	fk[n] = fun(n - 2, dp, u) or fun(n - 1, dp, u)
	return fk[n]

def check(dp, u, n):
	dp = dp[1:]
	for i in range(n + 1):
		if dp[i] < u[i]:
			return False
	return True

def fun(covered, k, right):
	f = 0
	maxCnt = 0
	maxEl = -1
	cntArr = [0] * 201
	for i in range(len(covered)):
		if len(covered[i]) <= k:
			continue
		else:
			for j in covered[i]:
				cntArr[j] = right[j]
			f = 1
			break
	if f == 0:
		return -1
	maxEl = cntArr.index(max(cntArr))
	return maxEl

def solve(_):
	(n, k) = li()
	covered = [[] for i in range(201)]
	right = [0] * 201
	for i in range(n):
		(l, r) = li()
		l -= 1
		r -= 1
		right[i] = r
		for j in range(l, r + 1):
			covered[j].append(i)
	back = covered[:]
	rem = []
	while 1:
		x = fun(covered, k, right)
		if x == -1:
			break
		rem.append(x + 1)
		for j in range(len(covered)):
			if x in covered[j]:
				covered[j].remove(x)
	print(len(rem))
	print(*rem)
t = 1
for _ in range(t):
	solve(_)


(n, k) = map(int, input().split())
p = []
t = [0] * 200
for i in range(n):
	(l, r) = map(int, input().split())
	p.append((i + 1, l, r))
p.sort(key=lambda x: x[1])
r = []
opened = []
for pp in p:
	opened = list(filter(lambda x: x[2] >= pp[1], opened))
	opened.append(pp)
	if len(opened) > k:
		opened.sort(key=lambda x: x[2])
		(x, _, _) = opened.pop()
		r.append(x)
print(len(r))
print(*r)


import os, sys
from io import BytesIO, IOBase

class SortedList:

	def __init__(self, iterable=None, _load=200):
		if iterable is None:
			iterable = []
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	(n, k) = map(int, input().split())
	seg = [tuple(map(int, input().split())) for _ in range(n)]
	dis = [[] for _ in range(2 * 10 ** 5 + 2)]
	for (ind, i) in enumerate(seg):
		dis[i[0]].append(ind + 1)
		dis[i[1] + 1].append(-(ind + 1))
	curr = SortedList()
	ans = []
	for i in range(2 * 10 ** 5 + 2):
		for x in dis[i]:
			if x > 0:
				curr.add((seg[x - 1][1], x))
			else:
				curr.discard((seg[-x - 1][1], -x))
		while len(curr) > k:
			ans.append(curr.pop()[1])
	print(len(ans))
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
[n, k] = [int(i) for i in sys.stdin.readline().split()]
arr = [0] * 201
seg = []
for i in range(n):
	[l, r] = [int(j) for j in sys.stdin.readline().split()]
	seg.append([r, l, r, i + 1])
	for x in range(l, r + 1):
		arr[x] += 1
seg.sort(reverse=True)
ans_arr = []
inc = [0] * n
for w in range(n):
	done = 1
	val = 0
	for g in range(1, 201):
		if arr[g] > k:
			done = 0
			val = g
			break
	if done == 1:
		break
	else:
		cur = n + 2
		for q in range(n):
			if inc[q] == 0:
				l1 = seg[q][1]
				r1 = seg[q][2]
				if l1 <= val <= r1:
					inc[q] = 1
					cur = q
					ans_arr.append(seg[q][3])
					break
		for p in range(seg[cur][1], seg[cur][2] + 1):
			arr[p] -= 1
ans_arr.sort()
print(len(ans_arr))
for e in range(len(ans_arr)):
	print(ans_arr[e], end=' ')


import sys
from heapq import *
(n, k) = map(int, input().split())
N = int(200000.0 + 2)
ll = [[] for _ in range(N)]
rr = [[] for _ in range(N)]
vis = [0] * N
for i in range(n):
	(l, r) = map(int, sys.stdin.readline().split())
	ll[l].append((-r, i + 1))
	rr[r].append(i + 1)
q = []
ans = []
size = 0
for i in range(1, N):
	for j in ll[i]:
		heappush(q, j)
		size += 1
	while size > k:
		cur = heappop(q)
		vis[cur[1]] = 1
		ans.append(cur[1])
		size -= 1
	for j in rr[i]:
		if not vis[j]:
			vis[j] = 1
			size -= 1
print(len(ans))
print(*ans)


from bisect import insort_left as bs
b = []
a = []
(n, k) = map(int, input().split())
for i in range(n):
	(x, y) = map(int, input().split())
	a.append([x, y, i + 1])
	b.append([x, y, i + 1])
a.sort()
ans = [[a[0][1], a[0][2]]]
le = 1
vis = [0] * 201
printans = []
for i in a:
	(x, y, ind) = (i[0], i[1], i[2])
	if i != a[0]:
		bs(ans, [y, ind], 0, le)
		le += 1
	for j in range(x, y + 1):
		if vis[j] >= k:
			(p, q) = ans.pop()
			le -= 1
			for l in range(b[q - 1][0], p + 1):
				vis[l] -= 1
			printans.append(q)
			for l in range(x, y + 1):
				vis[l] += 1
			break
	else:
		for j in range(x, y + 1):
			vis[j] += 1
print(len(printans))
print(*printans)


(n, k) = [int(x) for x in input().split()]
N = 210
cnt = [0] * N
segs = []
for _ in range(n):
	(l, r) = [int(x) for x in input().split()]
	segs.append([l, r])
	cnt[l] += 1
	cnt[r + 1] -= 1
for i in range(N - 1):
	cnt[i + 1] += cnt[i]
ans = []
for i in range(N):
	while cnt[i] > k:
		flag = -1
		idx = -1
		for j in range(n):
			(l, r) = segs[j]
			if l <= i and r > flag:
				flag = segs[j][1]
				idx = j
		ans.append(idx)
		for j in range(segs[idx][0], segs[idx][1] + 1):
			cnt[j] -= 1
		segs[idx][0] = N + 1
print(len(ans))
print(' '.join([str(x + 1) for x in ans]))


N = 250
(n, k) = map(int, input().split())
segs = [[0, 0] for _ in range(n)]
cnt = [0] * N
ans = [0] * n
for i in range(n):
	(segs[i][0], segs[i][1]) = map(int, input().split())
	cnt[segs[i][0]] += 1
	cnt[segs[i][1] + 1] -= 1
for i in range(N - 1):
	cnt[i + 1] += cnt[i]
for i in range(N - 1):
	while cnt[i] > k:
		pos = -1
		for p in range(n):
			if not ans[p] and segs[p][0] <= i <= segs[p][1] and (pos == -1 or segs[p][1] > segs[pos][1]):
				pos = p
		assert pos != -1
		for j in range(segs[pos][0], segs[pos][1] + 1):
			cnt[j] -= 1
		ans[pos] = 1
print(ans.count(1))
for i in range(n):
	if ans[i]:
		print(i + 1, end=' ')
print()


from heapq import *
(n, k) = map(int, input().split())
E = []
opent = {}
clos = {}
for i in range(n):
	(l, r) = map(int, input().split())
	E.append([l, 1, i])
	E.append([r, -1, i])
	opent[i] = r
	clos[i] = l
E.sort(key=lambda x: (x[0], -x[1], -opent[x[2]]))
b = 0
now_r = []
heapify(now_r)
cnt_delet = 0
ans = []
deleted = set()
for (x, t, i) in E:
	if t == 1:
		heappush(now_r, -(opent[i] * 10 ** 6 + i))
	elif i not in deleted:
		cnt_delet += 1
	if len(now_r) - cnt_delet > k:
		for _ in range(len(now_r) - cnt_delet - k):
			nm = heappop(now_r)
			ind = -nm % 10 ** 6
			ans.append(ind + 1)
			deleted.add(ind)
print(len(ans))
print(*ans)


(n, k) = map(int, input().strip().split())
seg = []
for i in range(n):
	(a, b) = map(int, input().strip().split())
	seg.append((a, b, i))
seg.sort()
cur_seg = set()
cur_num = 0
cur_index = 0
ans = set()
for i in range(1, 201):
	to_remove = []
	for e_seg in cur_seg:
		if i > e_seg[1]:
			to_remove.append(e_seg)
	for re in to_remove:
		cur_seg.remove(re)
	while cur_index < n:
		if seg[cur_index][0] <= i and seg[cur_index][1] >= i:
			cur_seg.add(seg[cur_index])
			cur_index += 1
		else:
			break
	cur_num = len(cur_seg)
	while cur_num > k:
		right_most = 0
		right_index = 0
		for e_seg in cur_seg:
			if e_seg[1] > right_most:
				right_most = e_seg[1]
				right_index = e_seg
		ans.add(right_index[2])
		cur_seg.remove(right_index)
		cur_num -= 1
print(len(ans))
print(' '.join((str(i + 1) for i in ans)))


import functools
from math import inf

class event:

	def __init__(self, x, type, index):
		self.x = x
		self.type = type
		self.i = index

def custom_sort(a, b):
	if a.x < b.x:
		return -1
	if a.x > b.x:
		return 1
	if a.type == 'e' and b.type == 's':
		return 1
	if a.type == 's' and b.type == 'e':
		return -1
	return 0
line = input().split(' ')
(n, k) = (int(line[0]), int(line[1]))
events = []
original_events = []
for i in range(n):
	line = input().split(' ')
	s = int(line[0])
	e = int(line[1])
	events.append(event(s, 's', i))
	events.append(event(e, 'e', i))
	original_events.append([s, e])
events.sort(key=functools.cmp_to_key(custom_sort))
active = []
ans = []
cnt = 0
for curr in events:
	if curr.type == 's':
		cnt += 1
		active.append(curr.i)
		if cnt > k:
			to_remove = 0
			rightmost = -inf
			to_remove_j = 0
			for j in range(len(active)):
				i = active[j]
				if original_events[i][1] > rightmost:
					rightmost = original_events[i][1]
					to_remove = i
					to_remove_j = j
			ans.append(str(to_remove + 1))
			active.pop(to_remove_j)
			cnt -= 1
	else:
		for j in range(len(active)):
			if active[j] == curr.i:
				cnt -= 1
				active.pop(j)
				break
print(len(ans))
print(' '.join(ans))


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def main():
	(n, k) = map(int, input().split())
	(a, ma) = ([], 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		a.append((l, r, i))
		ma = max(ma, r)
	b = [0] * (ma + 2)
	for i in a:
		b[i[0]] += 1
		b[i[1] + 1] -= 1
	for i in range(1, ma + 2):
		b[i] += b[i - 1]
	(ans, c, d) = ([], [0] * (ma + 2), set())
	for i in range(1, ma + 1):
		c[i] += c[i - 1]
		if b[i] + c[i] > k:
			e = []
			for j in a:
				if j not in d and j[1] >= i and (j[0] <= i):
					e.append(j)
			e.sort(key=lambda x: x[1] - i)
			z = b[i] + c[i] - k
			c[i] -= z
			while z:
				y = e.pop()
				c[y[1] + 1] += 1
				d.add(y)
				ans.append(y[-1] + 1)
				z -= 1
	print(len(ans))
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
(n, k) = map(int, input().split())
i = []
all_offenders = []
for q in range(n):
	i.append((tuple(map(int, input().split())), q))
i.sort(key=lambda x: x[0][1])
for t in range(200):
	count = 0
	offenders = []
	for pos in range(len(i)):
		if i[pos][0][0] <= t <= i[pos][0][1]:
			count += 1
			if count > k:
				offenders.append(pos)
				all_offenders.append(i[pos][1] + 1)
	offenders.reverse()
	for y in offenders:
		i.pop(y)
print(len(all_offenders))
print(*all_offenders)


import sys
input = sys.stdin.readline

class LLNode:

	def __init__(self, l, r, i):
		self.l = l
		self.r = r
		self.i = i
		self.next = None

	def __str__(self):
		return f"{(self.l, self.r)}, i={self.i}, next={('Node' if self.next else None)}"

class LL:

	def __init__(self):
		self.head = None

	def append(self, l, r, i):
		new_node = LLNode(l, r, i)
		if not self.head:
			self.head = new_node
			return
		cur_node = self.head
		while cur_node.next:
			cur_node = cur_node.next
		cur_node.next = new_node

	def get_delete_best(self, point):
		best_node = None
		best_r = -1
		best_prev = None
		prev = None
		node = self.head
		while node:
			if node.l <= point <= node.r and node.r > best_r:
				best_r = node.r
				best_prev = prev
				best_node = node
			prev = node
			node = node.next
		if best_node == self.head:
			self.head = best_node.next
			return best_node
		else:
			best_prev.next = best_node.next
			return best_node

	def __iter__(self):
		node = self.head
		while node:
			yield node
			node = node.next

	def __str__(self):
		return ' '.join((str((s.l, s.r)) for s in self.__iter__()))

	def __eq__(self, other):
		return self.i == other.i

def pop_best(segments, point):
	best_idx = None
	best_r = -1
	for (idx, seg) in enumerate(segments):
		if seg.l <= point <= seg.r and seg.r > best_r:
			best_r = seg.r
			best_idx = idx
	return segments.pop(best_idx)

def solve(n, k, segments, MIN_L, MAX_R):
	k_vals = [0] * (MAX_R + 1)
	del_segments = []
	for seg in segments:
		(l, r) = (seg.l, seg.r)
		for i in range(l, r + 1):
			k_vals[i] += 1
	for point in range(MIN_L, MAX_R + 1):
		while k_vals[point] > k:
			seg = pop_best(segments, point)
			del_segments.append(seg.i)
			for j in range(seg.l, seg.r + 1):
				k_vals[j] -= 1
	print(len(del_segments))
	print(*del_segments)
from collections import namedtuple
seg = namedtuple('seg', 'l, r, i')
(n, k) = map(int, input().split())
segments = []
MIN_L = 201
MAX_R = 0
for i in range(1, n + 1):
	(l, r) = map(lambda x: int(x) - 1, input().split())
	MAX_R = max(r, MAX_R)
	MIN_L = min(MIN_L, l)
	segments.append(seg(l, r, i))
solve(n, k, segments, MIN_L, MAX_R)


(n, k) = map(int, input().split())
segs = []
points = {}
removed = [False for i in range(n)]
for s in range(n):
	(l, r) = map(int, input().split())
	for i in range(l, r + 1):
		if not points.get(i):
			points[i] = []
		points[i].append([r, s])
	segs.append([l, r])
for i in points:
	points[i].sort(reverse=True)
r = 0
res = []
for i in sorted(points.keys()):
	needed = len(points[i])
	c = []
	for j in range(len(points[i])):
		if removed[points[i][j][1]]:
			needed -= 1
		else:
			c.append(points[i][j])
	if needed <= k:
		continue
	p = 0
	for t in range(needed - k):
		if not removed[c[t][1]]:
			r += 1
			res.append(c[t][1] + 1)
			removed[c[t][1]] = True
print(r)
print(*res)


class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class OrderedList(SortedList):

	def __init__(self, arg):
		super().__init__(arg)

	def rangeCountByValue(self, leftVal, rightVal):
		leftCummulative = self.bisect_left(leftVal)
		rightCummulative = self.bisect_left(rightVal + 1)
		return rightCummulative - leftCummulative

def main():
	(n, k) = readIntArr()
	lr = []
	for i in range(n):
		(l, r) = readIntArr()
		lr.append([l, r, i + 1])
	lr.sort(key=lambda x: x[0])
	storedRandI = OrderedList([])
	ans = []
	cnts = 0
	for (l, r, i) in lr:
		while storedRandI and storedRandI[0][0] < l:
			storedRandI.pop(0)
			cnts -= 1
		storedRandI.add([r, i])
		cnts += 1
		while cnts > k:
			(r, i) = storedRandI.pop(-1)
			cnts -= 1
			ans.append(i)
	print(len(ans))
	oneLineArrayPrint(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


from heapq import heapify, heappop, heappush
(n, k) = list(map(int, input().split()))
N = 2 * 10 ** 5 + 2
segs = []
plus = [0 for _ in range(N)]
minus = [0 for _ in range(N)]
ans = []
heapmin = []
heapmax = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	heappush(heapmin, (x - 1, y - 1, i + 1))
height = 0
for i in range(N):
	height += plus[i]
	height -= minus[i]
	while len(heapmin) > 0 and heapmin[0][0] <= i:
		(x, y, ii) = heappop(heapmin)
		heappush(heapmax, (-y, x, ii))
		height += 1
		minus[y + 1] += 1
	while height > k:
		(y, x, ii) = heappop(heapmax)
		y = -y
		height -= 1
		plus[y + 1] += 1
		ans.append(ii)
print(len(ans))
print(*ans)


import heapq
(n, k) = map(int, input().split())
st = []
L = [0] * 200005
for i in range(0, n):
	(l, r) = map(int, input().split())
	st.append((r, l, i + 1))
	L[l] += 1
	L[r + 1] -= 1
pre = [0]
for i in range(1, len(L)):
	pre.append(pre[-1] + L[i])
st2 = sorted(st)
st2 = st2[::-1]
dp = []
for i in range(0, 200005):
	h = []
	dp.append(h)
for i in range(0, len(st2)):
	dp[st2[i][1]].append(i + 1)
	dp[st2[i][0] + 1].append(-i - 1)
tot = 0
ans = []
pos = [0] * 200005
yaad = [0] * (n + 2)
q = []
heapq.heapify(q)
c = 0
for i in range(1, 200002):
	c = c + pos[i]
	for j in range(0, len(dp[i])):
		if dp[i][j] > 0:
			yaad[dp[i][j]] += 1
			heapq.heappush(q, dp[i][j])
		else:
			yaad[-dp[i][j]] -= 1
	if pre[i] - c > k:
		c2 = 0
		while pre[i] - c > k:
			tt = heapq.heappop(q)
			if yaad[tt] > 0:
				tot += 1
				ans.append(st2[tt - 1][2])
				pos[st2[tt - 1][0] + 1] -= 1
				c2 += 1
				pre[i] -= 1
		c += c2
if len(ans) > 0:
	ans = sorted(ans)
print(tot)
print(*ans)


import sys
import bisect
import heapq
line_count = 0
segments = [None]
num_points = 200000
for line in sys.stdin.readlines():
	inputs = line.split()
	if line_count == 0:
		n = int(inputs[0])
		k = int(inputs[1])
		opening = {}
		closing = {}
		removed_right = {}
		segment_index = 0
		for i in range(1, num_points + 1):
			opening[i] = []
			closing[i] = []
			removed_right[i] = 0
	else:
		l = int(inputs[0])
		r = int(inputs[1])
		segment_index += 1
		segments.append((l, r))
		opening[l].append(segment_index)
		closing[r].append(segment_index)
	if line_count == n:
		break
	line_count += 1
working = []
working_count = 0
removed = []
for i in range(1, num_points + 1):
	for segment_index in opening[i]:
		(_, r) = segments[segment_index]
		heapq.heappush(working, (-r, segment_index))
		working_count += 1
	while working_count > k:
		(r, segment_index) = heapq.heappop(working)
		working_count -= 1
		removed.append(segment_index)
		removed_right[-r] += 1
	squeezed_out = len(closing[i]) - removed_right[i]
	working_count -= squeezed_out
print(len(removed))
for j in removed:
	print(j, end=' ')


from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())

def solve():
	(n, k) = ri()
	A = [0] * 300
	mx = 0
	seg = []
	for i in range(n):
		(l, r) = ri()
		seg.append((l, r, i))
		A[l] += 1
		A[r + 1] -= 1
	seg.sort(key=lambda x: (x[0], x[1]))
	q = deque(seg)
	curr = 0
	ans = []
	for i in range(300):
		curr += A[i]
		use = []
		for (start, end, j) in seg:
			if start <= i <= end:
				use.append((start, end, j))
		use.sort(key=lambda x: x[1])
		while use and curr > k:
			(_, end, j) = use.pop()
			seg.remove((_, end, j))
			A[end + 1] += 1
			ans.append(j + 1)
			curr -= 1
	print(len(ans))
	print(*ans)
t = 1
while t:
	t -= 1
	solve()


(n, k) = map(int, input().split())
i = []
all_offenders = []
for q in range(n):
	i.append((tuple(map(int, input().split())), q))
i.sort(key=lambda x: x[0][1])
for t in range(200):
	count = 0
	offenders = []
	for pos in range(len(i)):
		if i[pos][0][0] <= t <= i[pos][0][1]:
			count += 1
			if count > k:
				offenders.append(pos)
				all_offenders.append(i[pos][1] + 1)
	offenders.reverse()
	for y in offenders:
		i.pop(y)
print(len(all_offenders))
print(*all_offenders)


[n, k] = [int(i) for i in input().split()]
a = []
min_i = 1
max_i = 2 * 10 ** 2
for i in range(n):
	a.append([int(i) for i in input().split()])
sor_ind = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
n_seg = 0
j = 0
curr = {}
rem_seg = []
for i in range(min_i, max_i + 1):
	while j < n and a[sor_ind[j]][0] == i:
		end_j = a[sor_ind[j]][1]
		n_seg += 1
		if end_j not in curr:
			curr[end_j] = [sor_ind[j]]
		else:
			curr[end_j].append(sor_ind[j])
		j += 1
	while n_seg > k:
		rem_seg.append(str(curr[max(curr)].pop() + 1))
		if len(curr[max(curr)]) == 0:
			curr.pop(max(curr))
		n_seg -= 1
	if i in curr:
		rem_i = curr.pop(i)
		n_seg -= len(rem_i)
print(len(rem_seg))
print(' '.join(rem_seg))


import functools
from math import inf

class event:

	def __init__(self, x, type, index):
		self.x = x
		self.type = type
		self.i = index

def custom_sort(a, b):
	if a.x < b.x:
		return -1
	if a.x > b.x:
		return 1
	if a.type == 'e' and b.type == 's':
		return 1
	if a.type == 's' and b.type == 'e':
		return -1
	return 0

def __starting_point():
	line = input().split(' ')
	(n, k) = (int(line[0]), int(line[1]))
	events = []
	original_events = []
	for i in range(n):
		line = input().split(' ')
		s = int(line[0])
		e = int(line[1])
		events.append(event(s, 's', i))
		events.append(event(e, 'e', i))
		original_events.append([s, e])
	events.sort(key=functools.cmp_to_key(custom_sort))
	active = {}
	ans = []
	cnt = 0
	for curr in events:
		if curr.type == 's':
			cnt += 1
			active[curr.i] = 1
			if cnt > k:
				to_remove = 0
				rightmost = -inf
				for i in active.keys():
					if original_events[i][1] > rightmost:
						rightmost = original_events[i][1]
						to_remove = i
				ans.append(str(to_remove + 1))
				del active[to_remove]
				cnt -= 1
		elif curr.i in active.keys():
			cnt -= 1
			del active[curr.i]
	print(len(ans))
	print(' '.join(ans))
__starting_point()


import heapq
(n, k) = map(int, input().split())
llis = [[] for i in range(2 * 10 ** 5 + 1)]
rlis = [[] for i in range(2 * 10 ** 5 + 1)]
flag = [0] * (2 * 10 ** 5 + 1)
for i in range(n):
	(l, r) = map(int, input().split())
	llis[l].append([i + 1, r])
	rlis[r].append([i + 1, l])
now = 0
rq = []
ans = []
for i in range(2 * 10 ** 5):
	i += 1
	for j in llis[i]:
		now += 1
		ind = j[0]
		r = j[1]
		flag[ind] = 1
		heapq.heappush(rq, [-1 * r, ind])
	for j in rlis[i - 1]:
		ind = j[0]
		if flag[ind] == 1:
			now -= 1
			flag[ind] = 0
	while now > k:
		nowq = heapq.heappop(rq)
		ind = nowq[1]
		if flag[ind] == 1:
			ans.append(ind)
			now -= 1
			flag[ind] = 0
print(len(ans))
print(' '.join(map(str, ans)))


import heapq
(N, K) = [int(x) for x in input().split()]
h = [[] for i in range(200000)]
for i in range(N):
	(l, r) = [int(x) for x in input().split()]
	h[l - 1].append([-(r - 1), i + 1])
g = []
t = []
heapq.heapify(t)
hist = [0] * 200000
exited = 0
for l in range(200000):
	for ri in h[l]:
		heapq.heappush(t, ri)
		hist[-ri[0]] += 1
	while len(t) - exited > K:
		top = heapq.heappop(t)
		hist[-top[0]] -= 1
		g.append(top[1])
	exited += hist[l]
print(len(g))
print(*g)


import heapq
(N, K) = [int(x) for x in input().split()]
L2RI = [[] for i in range(200000)]
for i in range(N):
	(l, r) = [int(x) for x in input().split()]
	L2RI[l - 1].append([-(r - 1), i + 1])
ans = []
que = []
heapq.heapify(que)
hist = [0] * 200000
exited = 0
for l in range(200000):
	for ri in L2RI[l]:
		heapq.heappush(que, ri)
		hist[-ri[0]] += 1
	while len(que) - exited > K:
		top = heapq.heappop(que)
		hist[-top[0]] -= 1
		ans.append(top[1])
	exited += hist[l]
print(len(ans))
print(*ans)


from functools import cmp_to_key
(n, k) = list(map(int, input().split()))
rg = []
f = [0 for i in range(202)]
for i in range(n):
	(l, r) = list(map(int, input().split()))
	rg.append((l, r, i + 1))
	f[l] += 1
	f[r + 1] -= 1

def my_cmp(x, y):
	if x[1] == y[1]:
		return x[0] - y[0]
	return y[1] - x[1]
rg.sort(key=cmp_to_key(my_cmp))
rg.insert(0, (0, 0))
rem = []
ha = {}
for i in range(1, 202):
	f[i] += f[i - 1]
	if f[i] > k:
		rem.append(i)
		ha[i] = f[i] - k
ans = []
while len(rem):
	i = 1
	while rg[i][0] > rem[0]:
		i += 1
	ans.append(rg[i][2])
	for j in range(len(rem)):
		if rem[j] >= rg[i][0] and rem[j] <= rg[i][1]:
			ha[rem[j]] -= 1
			if ha[rem[j]] == 0:
				rem[j] = 0
		else:
			break
	rem = [k for k in rem if k != 0]
	rg.pop(i)
print(len(ans))
ans = sorted(ans)
print(' '.join(map(str, ans)))


import heapq

def main():
	(n, k) = readIntArr()
	lr = []
	for i in range(n):
		(l, r) = readIntArr()
		lr.append([l, r, i + 1])
	lr.sort(key=lambda x: x[0])
	ans = []
	cnts = 0

	def getMinR(storedRandI):
		n = len(storedRandI)
		(minR, ii) = storedRandI[0]
		idx = 0
		for j in range(1, n):
			if storedRandI[j][0] < minR:
				(minR, ii) = storedRandI[j]
				idx = j
		return [minR, ii, idx]

	def getMaxR(storedRandI):
		n = len(storedRandI)
		(maxR, ii) = storedRandI[0]
		idx = 0
		for j in range(1, n):
			if storedRandI[j][0] > maxR:
				(maxR, ii) = storedRandI[j]
				idx = j
		return [maxR, ii, idx]
	storedRandI = []
	ans = []
	cnts = 0
	for (l, r, i) in lr:
		while storedRandI and getMinR(storedRandI)[0] < l:
			(minR, ii, idx) = getMinR(storedRandI)
			storedRandI.pop(idx)
			cnts -= 1
		storedRandI.append([r, i])
		cnts += 1
		while cnts > k:
			(maxR, ii, idx) = getMaxR(storedRandI)
			storedRandI.pop(idx)
			cnts -= 1
			ans.append(ii)
	print(len(ans))
	oneLineArrayPrint(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import sys, heapq
mmx = 200000
ftree = [0] * (mmx + 1)

def uu(i, j, v):
	while i <= mmx:
		ftree[i] += v
		i += i & -i
	j += 1
	while j <= mmx:
		ftree[j] -= v
		j += j & -j

def qq(j):
	s = 0
	while j > 0:
		s += ftree[j]
		j -= j & -j
	return s
(n, k) = [int(i) for i in sys.stdin.readline().split()]
lns = sys.stdin.readlines()
bds = []
for j in range(n):
	t = [int(i) for i in lns[j].split()]
	t.append(j + 1)
	bds.append(t)
	uu(bds[-1][0], bds[-1][1], 1)
bds.sort()
bind = 0
heap = []
ans = []
for i in range(1, mmx + 1):
	while bind < n and bds[bind][0] == i:
		heapq.heappush(heap, (-1 * bds[bind][1], bds[bind][2]))
		bind += 1
	while qq(i) > k:
		(bd, bnd) = heapq.heappop(heap)
		ans.append(str(bnd))
		uu(i, -1 * bd, -1)
print(len(ans))
print(' '.join(ans))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()

def segfunc(x, y):
	return x + y

class LazySegTree_RAQ:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		self.lazy = [0] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def gindex(self, l, r):
		l += self.num
		r += self.num
		lm = l >> (l & -l).bit_length()
		rm = r >> (r & -r).bit_length()
		while r > l:
			if l <= lm:
				yield l
			if r <= rm:
				yield r
			r >>= 1
			l >>= 1
		while l:
			yield l
			l >>= 1

	def propagates(self, *ids):
		for i in reversed(ids):
			v = self.lazy[i]
			if v == 0:
				continue
			self.lazy[i] = 0
			self.lazy[2 * i] += v
			self.lazy[2 * i + 1] += v
			self.tree[2 * i] += v
			self.tree[2 * i + 1] += v

	def add(self, l, r, x):
		(*ids,) = self.gindex(l, r)
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				self.lazy[l] += x
				self.tree[l] += x
				l += 1
			if r & 1:
				self.lazy[r - 1] += x
				self.tree[r - 1] += x
			r >>= 1
			l >>= 1
		for i in ids:
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) + self.lazy[i]

	def query(self, l, r):
		(*ids,) = self.gindex(l, r)
		self.propagates(*ids)
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res
(n, k) = inpl()
segs = []
for i in range(n):
	(l, r) = inpl()
	segs.append((l, r, i + 1))
segs.sort(key=lambda x: x[1])
st = LazySegTree_RAQ([0] * 200010, max, -1)
res = []
for (l, r, i) in segs:
	if st.query(l, r + 1) < k:
		st.add(l, r + 1, 1)
	else:
		res.append(i)
print(len(res))
print(*res)


import sys
from heapq import *
(n, k) = map(int, input().split())
seg = []
for i in range(n):
	(l, r) = map(int, input().split())
	seg.append((l, r, i + 1))
seg.sort()
c = 0
res = []
i = 0
hmin = []
hmax = []
rem = set()
while i < n:
	(l, r, si) = seg[i]
	while i < n and seg[i][0] == l:
		(_, r, si) = seg[i]
		heappush(hmax, (-r, si))
		heappush(hmin, (r, si))
		i += 1
		c += 1
	while len(hmin) > 0 and hmin[0][0] < l:
		(mr, ind) = heappop(hmin)
		if ind not in rem:
			c -= 1
	while c > k:
		(mr, ind) = heappop(hmax)
		res.append(ind)
		rem.add(ind)
		c -= 1
print(len(res))
if len(res) > 0:
	print(' '.join(map(str, res)))


from math import *
(n, k) = map(int, input().split())
a = []
pre = [0 for i in range(205)]
for i in range(n):
	(u, v) = map(int, input().split())
	a.append([u, v, i + 1])
	for i in range(u, v + 1):
		pre[i] += 1
ans = []
a.sort()
i = 1
while 1:
	flag = 0
	for i in range(205):
		if pre[i] > k:
			flag = i
			break
	if flag == 0:
		break
	m = 0
	m1 = 0
	for i in range(n):
		if a[i][0] > flag:
			break
		if m < a[i][1]:
			m = a[i][1]
			m1 = i
	ans.append(a[m1][2])
	for i in range(a[m1][0], a[m1][1] + 1):
		pre[i] -= 1
	del a[m1]
	n -= 1
print(len(ans))
for i in ans:
	print(i, end=' ')
print()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return list(map(int, input().split()))

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class SegTreeIndex:

	def __init__(self, n, func, init):
		self.n = n
		self.func = func
		self.init = init
		n2 = 1
		while n2 < n:
			n2 <<= 1
		self.n2 = n2
		self.tree = [self.init] * (n2 << 1)
		self.index = [self.init] * (n2 << 1)
		for i in range(n2):
			self.index[i + n2] = i
		for i in range(n2 - 1, -1, -1):
			self.index[i] = self.index[i * 2]

	def update(self, i, x):
		i += self.n2
		self.tree[i] = x
		while i > 1:
			(left, right) = (min(i, i ^ 1), max(i, i ^ 1))
			if self.func(self.tree[left], self.tree[right]) == self.tree[left]:
				self.tree[i >> 1] = self.tree[left]
				self.index[i >> 1] = self.index[left]
			else:
				self.tree[i >> 1] = self.tree[right]
				self.index[i >> 1] = self.index[right]
			i >>= 1

	def query(self, a, b):
		l = a + self.n2
		r = b + self.n2
		s = (self.init, -1)
		while l < r:
			if r & 1:
				r -= 1
				res = self.func(s[0], self.tree[r])
				if res == s[0]:
					pass
				else:
					s = (self.tree[r], self.index[r])
			if l & 1:
				res = self.func(self.tree[l], s[0])
				if res == self.tree[l]:
					s = (self.tree[l], self.index[l])
				else:
					pass
				l += 1
			l >>= 1
			r >>= 1
		return s
(N, K) = MAP()
MAX = 200007
LRs = [[] for i in range(MAX + 2)]
R = [0] * (N + 1)
for i in range(N):
	(l, r) = MAP()
	LRs[l].append(i + 1)
	LRs[r + 1].append(-(i + 1))
	R[i + 1] = r
sti = SegTreeIndex(N + 1, max, -INF)
segcnt = 0
ans = []
removed = set()
for i in range(1, MAX + 2):
	for idx in LRs[i]:
		if idx > 0:
			sti.update(idx, R[idx])
			segcnt += 1
		else:
			idx = abs(idx)
			if idx not in removed:
				sti.update(idx, -INF)
				segcnt -= 1
	while segcnt > K:
		(mx, idx) = sti.query(0, N + 1)
		sti.update(idx, -INF)
		ans.append(idx)
		removed.add(idx)
		segcnt -= 1
print(len(ans))
print(*ans)


import sys

def input():
	return sys.stdin.readline().strip()
import heapq
maxn = 200005

def lowbit(x):
	return x & -x

def add(t, i, v):
	while i < len(t):
		t[i] += v
		i += lowbit(i)

def sum(t, i):
	ans = 0
	while i > 0:
		ans += t[i]
		i -= lowbit(i)
	return ans
trees = [0] * maxn
(n, k) = map(int, input().split(' '))
seg = []
points = [0] * maxn
cand = []
for i in range(n):
	(l, r) = map(int, input().split(' '))
	seg.append((l, r, i + 1))
	points[l] += 1
	points[r + 1] -= 1
st = 0
for i in range(maxn):
	st += points[i]
	if st > k:
		cand.append((i, st - k))
seg.sort(key=lambda x: (x[0], x[1]))
pq = []
j = 0
ans = []
for (i, v) in cand:
	v = v - sum(trees, i)
	if v <= 0:
		continue
	while j < n and seg[j][0] <= i:
		heapq.heappush(pq, (-seg[j][1], seg[j][0], seg[j][2]))
		j += 1
	for t in range(v):
		(r, l, idx) = heapq.heappop(pq)
		ans.append(idx)
		add(trees, l, 1)
		add(trees, -r + 1, -1)
print(len(ans))
print(*ans)


from heapq import *
maxn = 205
BIT = [0] * maxn
points = [0] * maxn
deleted_points = [0] * maxn
cand = []
segs = []
(n, k) = map(int, input().split())
for i in range(n):
	(l, r) = map(int, input().split())
	points[l] += 1
	points[r + 1] -= 1
	segs.append((l, r, i + 1))
segs.sort(key=lambda x: (x[0], x[1]))
st = 0
for i in range(maxn):
	st += points[i]
	if st - k > 0:
		cand.append((st - k, i))
ans = []
pq = []
j = 0
for (v, i) in cand:
	v = v - deleted_points[i]
	while j < n and segs[j][0] <= i:
		heappush(pq, (-segs[j][1], segs[j][0], segs[j][2]))
		j += 1
	for _ in range(v):
		(r, l, idx) = heappop(pq)
		ans.append(idx)
		for x in range(l, -r + 1):
			deleted_points[x] += 1
print(len(ans))
print(*ans)


(n, k) = map(int, input().split())
arr = []
for i in range(n):
	(l, r) = map(int, input().split())
	arr.append([r, l, i])
arr.sort()
ans = []
for i in range(201):
	s = 0
	a = []
	for j in arr:
		if i <= j[0] and i >= j[1]:
			s += 1
			if s > k:
				ans.append(j[2] + 1)
				a.append(j)
	for j in a:
		arr.remove(j)
print(len(ans))
print(*sorted(ans))


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : map(int, rd().strip().split())
(n, k) = rrd()
ll = [[] for _i in range(200005)]
rr = [[] for _i in range(200005)]
for i in range(n):
	(l, r) = rrd()
	ll[l].append([-r, i + 1])
	rr[r].append(i + 1)
from heapq import *
q = []
lenth = 0
ans = []
vis = [0] * 200005
for i in range(1, 200005):
	for j in ll[i]:
		heappush(q, j)
		lenth += 1
	while lenth > k:
		now = heappop(q)
		while vis[now[1]]:
			now = heappop(q)
		vis[now[1]] = 1
		ans.append(now[1])
		lenth -= 1
	for j in rr[i]:
		if not vis[j]:
			vis[j] = 1
			lenth -= 1
print(len(ans))
print(' '.join(map(str, ans)))


heap = [[1e+18, -1]]

def pop():
	global heap
	heap[1] = heap[-1]
	heap.pop()
	i = 1
	while 2 * i < len(heap):
		if 2 * i + 1 < len(heap) and heap[2 * i + 1] > heap[2 * i] and (heap[2 * i + 1] > heap[i]):
			(heap[i], heap[2 * i + 1]) = (heap[2 * i + 1], heap[i])
			i = 2 * i + 1
		elif heap[2 * i] > heap[i]:
			(heap[i], heap[2 * i]) = (heap[2 * i], heap[i])
			i = 2 * i
		else:
			break

def push(val):
	global heap
	heap.append(val)
	i = len(heap) - 1
	while heap[i // 2] < heap[i]:
		(heap[i // 2], heap[i]) = (heap[i], heap[i // 2])
		i //= 2

def top():
	return heap[1]
NMAX = 100010
start_at = [[] for i in range(NMAX)]
ans = []
sp = [0 for i in range(NMAX)]
(n, k) = [int(x) for x in input().split()]
for i in range(n):
	(st, dr) = [int(x) for x in input().split()]
	start_at[st].append([dr, i + 1])
for poz in range(1, NMAX):
	for i in start_at[poz]:
		push(i)
		sp[poz] += 1
		sp[i[0] + 1] -= 1
	sp[poz] += sp[poz - 1]
	while sp[poz] > k:
		(until, nr) = top()
		pop()
		ans.append(nr)
		sp[poz] -= 1
		sp[until + 1] += 1
print(len(ans))
print(' '.join([str(i) for i in ans]))


(n, k) = map(int, input().split())
segs = [0] * n
max_idx = 210
cnt = [0] * max_idx
for i in range(n):
	(l, r) = map(int, input().split())
	segs[i] = (l, r)
	cnt[l] += 1
	cnt[r + 1] -= 1
for i in range(max_idx - 1):
	cnt[i + 1] += cnt[i]
ans = [0] * n
for i in range(max_idx):
	while cnt[i] > k:
		pos = -1
		for p in range(n):
			if not ans[p] and segs[p][0] <= i <= segs[p][1] and (pos == -1 or segs[p][1] > segs[pos][1]):
				pos = p
		for j in range(segs[pos][0], segs[pos][1] + 1):
			cnt[j] -= 1
		ans[pos] = 1
print(sum(ans[0:n]))
for (i, v) in enumerate(ans):
	if v:
		print(i + 1, end=' ')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k) = map(int, input().split())
l = [0] * (2 * 10 ** 5 + 2)
ma = 0
rt = []
for i in range(n):
	(a, b) = map(int, input().split())
	rt.append((a, b, i + 1))
	ma = max(b, ma)
	l[a] += 1
	l[b + 1] -= 1
s1 = SegmentTree(l)
rt.sort()
t = 0
g = []
heapq.heapify(g)
ans = []
for i in range(1, ma + 1):
	cou = s1.query(0, i)
	while t < n and rt[t][0] <= i:
		heapq.heappush(g, (-rt[t][1], rt[t][0], rt[t][2]))
		t += 1
		if t == n:
			break
	if cou > k:
		c = cou - k
		for i in range(c):
			(r, l1, ind) = heapq.heappop(g)
			ans.append(ind)
			r *= -1
			l[l1] -= 1
			l[r + 1] += 1
			s1.__setitem__(l1, l[l1])
			s1.__setitem__(r + 1, l[r + 1])
print(len(ans))
print(*ans)


a = [0 for i in range(201)]
(n, y) = map(int, input().split())
b = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	b[i].append(i + 1)
c = []
flag = 0
b.reverse()
b.sort(key=lambda x: x[1])
j = 0
while j < len(b):
	for i in range(b[j][0], b[j][1] + 1):
		if b[j][0] <= i <= b[j][1]:
			a[i] += 1
		if a[i] > y:
			flag = 1
	if flag == 1:
		c.append(b[j][2])
		k = b[j][0]
		while k <= b[j][1]:
			a[k] -= 1
			k += 1
		b.__delitem__(j)
		j -= 1
		flag = 0
	j += 1
c.sort()
print(len(c))
print(' '.join(map(str, c)))


(n, k) = map(int, input().split())
maxi = 202
fr = [0] * maxi
segments = []
for i in range(n):
	(x, y) = map(int, input().split())
	segments.append([x, y])
	fr[y + 1] = fr[y + 1] - 1
	fr[x] = fr[x] + 1
for i in range(maxi - 1):
	fr[i + 1] = fr[i + 1] + fr[i]
final = []
for i in range(maxi):
	while k < fr[i]:
		ok = -1
		j = -1
		p = 0
		while p < n:
			(x, y) = segments[p]
			if x <= i:
				if y > ok:
					ok = segments[p][1]
					j = p
			p = p + 1
		final.append(j)
		for p in range(segments[j][0], segments[j][1] + 1):
			fr[p] = fr[p] - 1
		segments[j][0] = maxi + 1
nr = len(final)
print(nr)
print(' '.join([str(i + 1) for i in final]))


import heapq
(n, k) = map(int, input().split())
length = 2 * 10 ** 5
llist = [[] for x in range(length + 1)]
rlist = [[] for x in range(length + 1)]
flag = [0] * (length + 1)
for i in range(n):
	(l, r) = map(int, input().split())
	llist[l].append([i + 1, r])
	rlist[r].append([i + 1, l])
heap = []
ans = []
now = 0
for i in range(length):
	i += 1
	for j in llist[i]:
		now += 1
		currents = j[0]
		r = j[1]
		flag[currents] = 1
		heapq.heappush(heap, [-1 * r, currents])
	for j in rlist[i - 1]:
		currents = j[0]
		if flag[currents] == 1:
			now -= 1
			flag[currents] = 0
	while now > k:
		removing = heapq.heappop(heap)
		currents = removing[1]
		if flag[currents] == 1:
			ans.append(currents)
			now -= 1
			flag[currents] = 0
print(len(ans))
print(' '.join(map(str, ans)))


from sys import stdin
import heapq
(n, k) = [int(x) for x in stdin.readline().split()]
segs = []
axis = [0 for x in range(200)]
for seg in range(n):
	(l, r) = [int(x) for x in stdin.readline().split()]
	l -= 1
	segs.append((l, r, seg + 1))
segs.sort()
q = []
dummy = []
for (l, r, ind) in segs:
	heapq.heappush(q, (-r, l, ind))
	chill = True
	for x in range(l, r):
		axis[x] += 1
		if axis[x] > k:
			chill = False
	if not chill:
		(rR, rL, rInd) = heapq.heappop(q)
		rR *= -1
		dummy.append(rInd)
		for x in range(rL, rR):
			axis[x] -= 1
print(len(dummy))
print(' '.join([str(x) for x in dummy]))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import heapq as h
from collections import defaultdict
(n, ma) = map(int, input().split())
d = defaultdict(lambda : [])
he = []
dd = defaultdict(lambda : [])
for i in range(n):
	(l, r) = map(int, input().split())
	dd[r].append(i + 1)
	d[l].append([r, i + 1])
l = []
vis = [0] * (2 * 10 ** 5 + 2)
active = 0
for i in range(1, 2 * 10 ** 5 + 1):
	for k in d[i]:
		active += 1
		h.heappush(he, [-k[0], k[1]])
	while active > ma:
		var = h.heappop(he)
		while vis[var[1]] == 1:
			var = h.heappop(he)
		vis[var[1]] = 1
		l.append(var[1])
		active -= 1
	for j in dd[i]:
		if vis[j] == 0:
			vis[j] = 1
			active -= 1
print(len(l))
print(*l)


[n, k] = list(map(int, input().split(' ')))
arr = []
for index in range(n):
	inp = list(map(int, input().split(' ')))
	inp.append(index + 1)
	arr.append(inp)
arr.sort(key=lambda x: x[0])
pres = []
m = 0
rem = []
for segment in arr:
	pres = list(filter(lambda x: x[1] >= segment[0], pres))
	pres.append(segment)
	while len(pres) > k:
		maxi = max(pres, key=lambda x: x[1])
		pres.remove(maxi)
		m += 1
		rem.append(maxi[2])
print(m)
print(*rem)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import heapq

def main():
	(n, k) = map(int, input().split())
	segs = []
	dict1 = {}
	nums = 2 * 10 ** 5
	for s in range(n):
		(l, r) = map(int, input().split())
		segs.append((l, r, s + 1))
	segs.sort(key=lambda x: [x[0], x[1]])
	for s in range(n - 1, -1, -1):
		if not segs[s][1] in dict1:
			dict1[segs[s][1]] = [segs[s][2]]
		else:
			dict1[segs[s][1]].append(segs[s][2])
	heapy = []
	mark = [0 for s in range(nums + 2)]
	cv = 0
	tt = 0
	ans = []
	for point in range(1, nums + 1):
		while cv < n and segs[cv][0] <= point:
			heapq.heappush(heapy, -segs[cv][1])
			mark[segs[cv][1]] += 1
			cv += 1
		while len(heapy) > 0 and len(heapy) - tt > k:
			v0 = -heapq.heappop(heapy)
			if v0 >= point:
				ans.append(dict1[v0].pop())
				mark[v0] -= 1
			else:
				tt -= 1
				mark[v0] -= 1
		tt += mark[point]
	print(len(ans))
	print(*ans)
main()


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	(n, k) = inp()
	arr = []
	ans = []
	for i in range(n):
		arr.append(list(inp()))
	(big, small) = (-float('inf'), float('inf'))
	for i in range(n):
		big = max(max(arr[i]), big)
		small = min(min(arr[i]), small)
	mark = [True] * n
	for i in range(small, big + 1):
		while True:
			ch = []
			times = 0
			for pos in range(n):
				if mark[pos]:
					j = arr[pos]
					if i >= j[0] and i <= j[1]:
						times += 1
						ch.append(j)
			if times > k:
				right = -float('inf')
				for j in ch:
					if j[1] > right:
						ele = j
						right = j[1]
				for j in range(n):
					if mark[j]:
						if arr[j] == ele:
							p = j
							break
				ans.append(p + 1)
				mark[p] = False
			else:
				break
	print(len(ans))
	print(*ans)


import sys
(n, k) = map(int, input().split())
t = -1

def input():
	global t
	t += 1
	return data[t]
data = sys.stdin.readlines()
ls = []
rs = []
from heapq import heappop, heappush
inf = 2 * 10 ** 5 + 1
for i in range(n):
	(l, r) = map(int, input().split())
	ls.append(l)
	rs.append(r)
rs.append(inf)
line = list(range(n))
line2 = list(range(n))
line = [(ls[i], i, +1) for i in line] + [(rs[i], -1, i) for i in line2]
line.sort(key=lambda x: (x[0], rs[x[1]]))
count = 0
answer = set()
ends = []
use = [False] * n
for i in range(2 * n):
	(x, f, o) = line[i]
	if f >= 0:
		count += 1
		heappush(ends, (-rs[f], f))
	else:
		if count > k:
			d = count - k
			while d > 0:
				(h, j) = ends[0]
				heappop(ends)
				if not use[j]:
					answer.add(j)
					d -= 1
			count = k
		if o not in answer:
			count -= 1
		use[o] = True
print(len(answer))
answer = [i + 1 for i in answer]
print(*answer)


from math import *
(n, k) = map(int, input().split())
num = [[] for i in range(300)]
segment = [0]
for i in range(1, n + 1):
	(l, r) = map(int, input().split())
	num[l].append(i)
	num[r + 1].append(-i)
	segment.append((l, r + 1, r - l))
rep = 0
curSegment = []
rem = []
for i in range(300):
	for a in num[i]:
		if a >= 0:
			curSegment.append(a)
		elif -a in curSegment:
			curSegment.remove(-a)
	while len(curSegment) > k:
		rep += 1
		plusAdroite = 0
		aVirer = 0
		for j in curSegment:
			if segment[j][1] >= plusAdroite:
				plusAdroite = segment[j][1]
				aVirer = j
		curSegment.remove(aVirer)
		rem.append(aVirer)
print(rep)
print(*sorted(rem))


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	(n, k) = map(int, input().split())
	segment = []
	for i in range(n):
		(l, r) = map(int, input().split())
		segment.append((l, r, i + 1))
	ans = []
	D = [0] * 210
	for (l, r, idx) in segment:
		D[l] += 1
		D[r + 1] -= 1
	for i in range(1, 210):
		D[i] += D[i - 1]
	for R in range(200, 0, -1):
		if D[R] > k:
			rep = D[R] - k
			tmp_seg = list(filter(lambda x: x[0] <= R <= x[1], segment))
			not_used_seg = list(filter(lambda x: not x[0] <= R <= x[1], segment))
			tmp_seg.sort(key=lambda x: -x[0])
			for _ in range(rep):
				(l, r, idx) = tmp_seg.pop()
				ans.append(idx)
				for i in range(l, r + 1):
					D[i] -= 1
			segment = not_used_seg + tmp_seg
	print(len(ans))
	print(*ans)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


from sys import stdin, stdout
import heapq

class MyHeap(object):

	def __init__(self, initial=None, key=lambda x: x):
		self.key = key
		if initial:
			self._data = [(key(item), item) for item in initial]
			heapq.heapify(self._data)
		else:
			self._data = []

	def push(self, item):
		heapq.heappush(self._data, (self.key(item), item))

	def pop(self):
		return heapq.heappop(self._data)[1]

	def print(self):
		for hd in self._data:
			print(hd)
		print('-------------------------------')

def getremovesegments(list, k):
	res = []
	hp = MyHeap(key=lambda x: -x[1])
	list.sort()
	for item in list:
		hp.push(item)
		cov = 0
		for t in hp._data:
			if item[0] <= t[1][1]:
				cov += 1
		if cov > k:
			p = hp.pop()
			res.append(p[2])
	return res
nk = list(map(int, stdin.readline().strip().split()))
n = nk[0]
k = nk[1]
seglist = []
for i in range(n):
	lr = list(map(int, stdin.readline().strip().split()))
	lr.append(i + 1)
	seglist.append(lr)
res = getremovesegments(seglist, k)
stdout.write(str(len(res)) + '\n')
stdout.write(' '.join((str(x) for x in res)))


(n, k) = map(int, input().split())
s = []
for i in range(n):
	(l, r) = map(int, input().split())
	s.append([r, l, i])
s.sort()
ans = []
for i in range(201):
	a = 0
	u = []
	for tmp in s:
		if i <= tmp[0] and i >= tmp[1]:
			a += 1
			if a > k:
				u.append(tmp)
				ans.append(tmp[2] + 1)
	for tmp in u:
		s.remove(tmp)
print(len(ans))
print(' '.join(map(str, ans)))


from heapq import *

def main():
	(n, k) = map(int, input().split())
	E = []
	opent = {}
	for i in range(n):
		(l, r) = map(int, input().split())
		E.append([l, 1, i])
		E.append([r, -1, i])
		opent[i] = r
	E.sort(key=lambda x: (x[0], -x[1]))
	now_r = []
	heapify(now_r)
	cnt_delet = 0
	ans = []
	deleted = set()
	for (x, t, i) in E:
		if t == 1:
			heappush(now_r, -(opent[i] * 10 ** 6 + i))
		elif i not in deleted:
			cnt_delet += 1
		if len(now_r) - cnt_delet > k:
			for _ in range(len(now_r) - cnt_delet - k):
				nm = heappop(now_r)
				ind = -nm % 10 ** 6
				ans.append(ind + 1)
				deleted.add(ind)
	print(len(ans))
	print(' '.join(list(map(str, ans))))
main()


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [list(mp()) for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def fibo_n(n):
	return ((1 + sqrt(5)) / 2) ** n / sqrt(5)
mod = 1000000007
k = [0] * 203
(a, b) = mp()
d = dd(lambda : [[0, 0]])
al = []
for __ in range(a):
	(l, r) = mp()
	k[l] += 1
	k[r + 1] -= 1
	al.append([l, r, __ + 1])
al.sort()
for i in al:
	d[i[0]].append([i[1], i[2]])
(rem, sm) = ({}, 0)
for s in range(len(k)):
	sm += k[s]
	if sm > b:
		rem[s] = sm - b
curk = list(d.keys())
segments = set()
for bad in rem:
	while rem[bad] > 0:
		seg = 0
		prevseg = 0
		for ele in curk:
			if ele <= bad and len(d[ele]) > 1:
				seg = max(seg, d[ele][-1][0])
				if seg > prevseg:
					prevseg = seg
					start = ele
					ind = d[ele][-1][1]
		if seg > 0:
			segments.add(ind)
		d[start].pop()
		for bade in rem:
			if rem[bade] > 0 and bade >= start and (bade <= seg):
				rem[bade] -= 1
print(len(segments))
print(*sorted(segments))


import sys
line_count = 0
segments = []
for line in sys.stdin.readlines():
	inputs = line.split()
	if line_count == 0:
		n = int(inputs[0])
		k = int(inputs[1])
	else:
		l = int(inputs[0])
		r = int(inputs[1])
		segments.append((l, r))
	if line_count == n:
		break
	line_count += 1
removed = [False for i in range(n)]
remove_count = 0
removed_list = []
for i in range(1, 201):
	max_i = 0
	covering = []
	for j in range(n):
		if removed[j]:
			continue
		(l, r) = segments[j]
		if l <= i and i <= r:
			covering.append((r, j))
	to_remove = len(covering) - k
	if to_remove > 0:
		covering.sort()
		for _ in range(to_remove):
			(_, j) = covering.pop()
			removed[j] = True
			removed_list.append(j)
print(len(removed_list))
for j in removed_list:
	print(j + 1, end=' ')


import sys
from collections import deque
readline = sys.stdin.readline
(n, k) = map(int, readline().split())
tmp = []
for i in range(n):
	(a, b) = map(int, readline().split())
	tmp.append([b, a, i])
tmp.sort()
ans = []
for i in range(201):
	s = 0
	asd = []
	for x in tmp:
		if i <= x[0] and i >= x[1]:
			s += 1
			if s > k:
				ans.append(x[2] + 1)
				asd.append(x)
	for x in asd:
		tmp.remove(x)
print(len(ans))
for x in ans:
	print(x, end=' ')


class BIT:

	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i

	def mx_sum(self, i):
		s = -10 ** 18
		while i > 0:
			s += max(s, self.tree[i])
			i -= i & -i
		return s

	def mx_add(self, i, x):
		while i <= self.size:
			self.tree[i] += max(x, self.tree[i])
			i += i & -i

class RangeUpdate:

	def __init__(self, n):
		self.p = BIT(n + 1)
		self.q = BIT(n + 1)

	def add(self, s, t, x):
		t += 1
		self.p.add(s, -x * s)
		self.p.add(t, x * t)
		self.q.add(s, x)
		self.q.add(t, -x)

	def sum(self, s, t):
		t += 1
		return self.p.sum(t) + self.q.sum(t) * t - self.p.sum(s) - self.q.sum(s) * s

def main():
	(N, K) = (int(i) for i in input().split())
	LR = [([int(i) for i in input().split()], j + 1) for j in range(N)]
	LR.sort(key=lambda p: p[0][1])
	r = RangeUpdate(2 * 10 ** 5)
	ans = []
	for (lr, idx) in LR:
		if max((r.sum(i, i) for i in range(lr[0], lr[1] + 1))) < K:
			r.add(lr[0], lr[1], 1)
		else:
			ans.append(idx)
	print(len(ans))
	print(*ans)
main()


def toomany(arr, k):
	cnt = [0] * 300
	for i in arr:
		cnt[i[0]] += 1
		cnt[i[1] + 1] -= 1
	for i in range(0, 300 - 1):
		cnt[i + 1] += cnt[i]
	ans = [0] * len(arr)
	for i in range(300):
		while cnt[i] > k:
			pos = -1
			for p in range(len(arr)):
				if ans[p] == 0 and (arr[p][0] <= i and arr[p][1] >= i) and (pos == -1 or arr[p][1] > arr[pos][1]):
					pos = p
			if pos != -1:
				for j in range(arr[pos][0], arr[pos][1] + 1):
					cnt[j] -= 1
			ans[pos] = 1
	print(ans.count(1))
	for i in range(len(ans)):
		if ans[i] == 1:
			print(i + 1, end=' ')
	return ''
(a, b) = map(int, input().strip().split())
blanck = []
for i in range(a):
	(x, y) = map(int, input().strip().split())
	blanck.append([x, y])
print(toomany(blanck, b))