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

Difficulty: introductory

Starter code:

Solutions:
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,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])

# print(L)


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
# print(T)
A.sort()
print(ans)
print(" ".join([str(i) for i in A]))



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)

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)

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()

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 heapq

n,k = list(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 = list(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)))

        


from bisect import insort_left as bs
b=[]
a=[]
n,k=list(map(int,input().split()))
for i in range(n):
    x,y=list(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
                # print("cnkjsn")
            printans.append(q)    
            for l in range(x,y+1):
                vis[l]+=1
            # print(vis[28:31])
            break
    else:
        for j in range(x,y+1):
            vis[j]+=1
    # print(ans,vis[28:31])        
            
    # print(print(vis[1:10],ans)
    #     
    # )
    # print(vis[1:10],ans)
        
print(len(printans))
print(*printans)
    
        
        


import sys
input = sys.stdin.readline

n,k=list(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())# Segment treeの台の要素数
SEG=[0]*(2*seg_el)# 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

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,r)のminを更新.
    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))

    #print(getvalue(point,seg_el),SH)

    while getvalue(point,seg_el)>k:
        r,l,x=heapq.heappop(SH)
        r=-r
        ANS.append(x)
        updates(l,r+1,-1)

    #print(point,ANS,getvalue(point,seg_el))
        
print(len(ANS))
print(*ANS)
        


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))
    else:
        if 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)

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=' ')

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)

N = int(2e5+3)
cum = [0] * N
n, k = list(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)


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)

# -*- coding: utf-8 -*-

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()
#            print(i, j, segments[j])
            removed[j] = True
            removed_list.append(j)

print(len(removed_list))
for j in removed_list:
    print(j + 1, end = " ")

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=[]
# ind=0
inc=[0]*n

for w in range(n):
	# check
	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					

		# l1=seg[ind][1]
		# r1=seg[ind][2]

		for p in range(seg[cur][1],seg[cur][2]+1):
			arr[p]-=1

		# ans_arr.append(seg[ind][3])
		# ind+=1

ans_arr.sort()

print(len(ans_arr))
for e in range(len(ans_arr)):
	print(ans_arr[e],end=" ")






n, k = map(int, input().split())
s = []
for i in range(n):
    l, r = map(int, input().split())
    s.append([r, l, i]) # Greedy on largest right endpoint
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)))

'''
template author-: Pyduper
'''
 
# MAX = pow(10, 5)
# stdin = open("testdata.txt", "r")
# ip = stdin
# def input():
# 	return ip.readline().strip()

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()

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:
    #print("---")
    #print(pp)
    #print(opened)
    opened = list(filter(lambda x:x[2] >= pp[1], opened))
    #print(opened)
    opened.append(pp)
    #print(opened)
    if len(opened) > k:
        opened.sort(key=lambda x: x[2])
        x, _, _ = opened.pop()
        r.append(x)
print(len(r))

print(*r)

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)

# -*- coding: utf-8 -*-
 
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 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.i == b.i:
	# 	if a.type == "s" and b.type == "e":
	# 		return -1
	# 	if a.type == "e" and b.type == "s":
	# 		return 1
	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:
		# print(curr.x, curr.type, curr.i, cnt)
		if curr.type == "s":
			cnt += 1
			active[curr.i] = 1

			if cnt > k:
				# print("over:", curr.i, cnt)
				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

		else:
			if curr.i in active.keys():
				cnt -= 1
				del active[curr.i]

	print(len(ans))
	print(" ".join(ans))
__starting_point()

# -*- coding: utf-8 -*-

import sys
import bisect

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 = []
removed = []
for i in range(1, num_points + 1):
    for segment_index in opening[i]:
        _, r = segments[segment_index]
        bisect.insort_right(working, (r, segment_index))
    working_count = len(working)
    while working_count > k:
        r, segment_index = working.pop()
        working_count -= 1
        removed.append(segment_index)
        removed_right[r] += 1
    squeezed_out = len(closing[i]) - removed_right[i]
    working = working[squeezed_out: ]

print(len(removed))
for j in removed:
    print(j, end = " ")

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])