You are given a multiset $S$ initially consisting of $n$ distinct non-negative integers. A multiset is a set, that can contain some elements multiple times.

You will perform the following operation $k$ times:

Add the element $\lceil\frac{a+b}{2}\rceil$ (rounded up) into $S$, where $a = \operatorname{mex}(S)$ and $b = \max(S)$. If this number is already in the set, it is added again.

Here $\operatorname{max}$ of a multiset denotes the maximum integer in the multiset, and $\operatorname{mex}$ of a multiset denotes the smallest non-negative integer that is not present in the multiset. For example:

$\operatorname{mex}(\{1,4,0,2\})=3$;

$\operatorname{mex}(\{2,5,1\})=0$.

Your task is to calculate the number of distinct elements in $S$ after $k$ operations will be done.


-----Input-----

The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $n$, $k$ ($1\le n\le 10^5$, $0\le k\le 10^9$) — the initial size of the multiset $S$ and how many operations you need to perform.

The second line of each test case contains $n$ distinct integers $a_1,a_2,\dots,a_n$ ($0\le a_i\le 10^9$) — the numbers in the initial multiset.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print the number of distinct elements in $S$ after $k$ operations will be done.


-----Examples-----

Input
5
4 1
0 1 3 4
3 1
0 1 4
3 0
0 1 4
3 2
0 1 2
3 2
1 2 3
Output
4
4
3
5
3


-----Note-----

In the first test case, $S={0,1,3,4\}$, $a=\operatorname{mex}(S)=2$, $b=\max(S)=4$, $\lceil\frac{a+b}{2}\rceil=3$. So $3$ is added into $S$, and $S$ becomes $\{0,1,3,3,4\}$. The answer is $4$.

In the second test case, $S={0,1,4\}$, $a=\operatorname{mex}(S)=2$, $b=\max(S)=4$, $\lceil\frac{a+b}{2}\rceil=3$. So $3$ is added into $S$, and $S$ becomes $\{0,1,3,4\}$. The answer is $4$.

Difficulty: EASY

Solutions:
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	m = a[-1]
	if a[0] != 0:
		if (m + 1) // 2 in a:
			print(n)
		elif k == 0:
			print(n)
		else:
			print(n + 1)
	else:
		mex = 0
		for i in range(n):
			if a[i] != i:
				mex = i
				break
		if mex == 0 or mex == m - 1:
			print(n + k)
		elif (m + mex + 1) // 2 in a:
			print(n)
		elif k == 0:
			print(n)
		else:
			print(n + 1)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	if K == 0:
		print(N)
		continue
	ma = max(A)
	me = 0
	for a in sorted(A):
		if a == me:
			me += 1
	if ma < me:
		print(N + K)
		continue
	st = set(A)
	for i in range(K):
		add = (ma + me + 1) // 2
		if add in st:
			break
		st.add(add)
	print(len(st))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l = sorted(l)
	mex = -1
	for i in range(len(l)):
		if l[i] != i:
			mex = i
			break
	if mex == -1:
		mex = n
	mx = max(l)
	x = mx + mex
	if x % 2 == 0:
		x = x // 2
	else:
		x = x // 2 + 1
	if x == mx:
		print(len(l))
	elif x == mex:
		print(k + len(l))
	else:
		y = len(l)
		if x not in l and k > 0:
			y += 1
		print(y)


from collections import defaultdict
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	for i in l:
		d[i] += 1
	l.sort()
	mex = -1
	for i in range(n - 1):
		if l[i + 1] - l[i] > 1:
			mex = l[i] + 1
			break
	if mex == -1 and 0 in d:
		print(len(d) + k)
	else:
		if mex == -1:
			mex = 0
		if k == 0:
			print(len(d))
		elif math.ceil((l[-1] + mex) / 2) in d:
			print(len(d))
		else:
			print(len(d) + 1)


import math

def solve():
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	inside = [False] * (n + 1)
	maximal = max(a)
	for num in a:
		if num <= n:
			inside[num] = True
	mex = inside.index(False)
	if k == 0:
		return len(a)
	if mex == maximal + 1:
		return len(a) + k
	if math.ceil((mex + maximal) / 2) > n or not inside[math.ceil((mex + maximal) / 2)]:
		return len(a) + 1
	return len(a)
t = int(input())
while t > 0:
	t -= 1
	print(solve())


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = sorted(map(int, input().split()))
	mx = li[-1]
	if k == 0 or mx == n - 1:
		print(n + k)
		continue
	mex = 0
	i = 0
	while mex == li[i]:
		i += 1
		mex += 1
	check = ceil((mx + mex) / 2)
	if check in li:
		print(n)
	else:
		print(n + 1)


from math import *

def solve():
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	if k == 0:
		print(n)
		return
	m = max(l)
	val = -1
	for i in range(n):
		if i not in l:
			val = i
			break
	else:
		print(n + k)
		return
	if ceil((val + m) / 2) in l:
		print(n)
		return
	print(n + 1)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nums = set(map(int, input().split()))
	maX = max(nums)
	mex = 0
	while mex in nums:
		mex += 1
	if mex > maX or k == 0:
		print(n + k)
	else:
		print(n if (mex + maX + 1) // 2 in nums else n + 1)


R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, k) = R()
	a = {*R()}
	i = 0
	while {i} & a:
		i += 1
	print(n + (k > 0) * (k, i + max(a) + 1 >> 1 not in a)[i < n])


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*set(map(int, input().split()))]
	a.sort()
	mx = a[-1]
	mex = 0
	l = len(a)
	if k == 0:
		print(l)
	else:
		for i in range(l):
			if mex == a[i]:
				mex += 1
			elif mex < a[i]:
				break
		if mex > mx:
			print(l + k)
		elif math.ceil((mex + mx) / 2) in a:
			print(l)
		else:
			print(l + 1)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
from math import ceil
for _ in range(rn()):
	(n, k) = rns()
	s = rl()
	m = max(s)
	h = set(s)
	if k == 0:
		print(len(h))
	else:
		for i in range(10 ** 9 + 1):
			if i not in h:
				if i > m:
					print(len(h) + k)
				elif ceil((i + m) / 2) not in h:
					print(len(h) + 1)
				else:
					print(len(h))
				break


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	m1 = max(l)
	m2 = 0
	for i in range(m1 + 2):
		if i not in l:
			m2 = i
			break
	if m2 == m1 + 1:
		print(len(l) + k)
	else:
		if k > 0:
			l.add((m1 + m2 + 1) // 2)
		print(len(l))
	t -= 1


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
mi = lambda : map(int, input().split())
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
mati = lambda r: [li() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def solve():
	(n, k) = mi()
	arr = li()
	arr.sort()
	mex = -1
	for x in range(n):
		if arr[x] != x:
			mex = x
			break
	ans = len(list(set(arr)))
	if mex == -1:
		mex = arr[-1] + 1
		ans += k
	elif ceil((mex + max(arr)) / 2) not in arr and k > 0:
		ans += 1
	print(ans)
for _ in range(ii()):
	solve()


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	s = set(list(map(int, input().split())))
	arr = list(s)
	arr.sort()
	m = len(arr)
	maxi = max(arr)
	mex = m
	for i in range(m):
		if arr[i] != i:
			mex = i
			break
	if k == 0:
		print(m)
	else:
		r = int(math.ceil((mex + maxi) / 2))
		if r < mex:
			print(m)
		elif r > mex:
			if r in s:
				print(m)
			else:
				print(m + 1)
		elif r == mex:
			print(m + k)


def mex(arr):
	n = len(arr)
	v = set(arr)
	for i in range(0, n):
		if i not in v:
			return i
	return n + 1
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	arr = [int(num) for num in input().split(' ')]
	if k == 0:
		ans = n
	else:
		a = mex(arr)
		b = max(arr)
		if a > b:
			ans = n + k
		else:
			f = ceil((a + b) / 2)
			if f not in arr:
				ans = n + 1
			else:
				ans = n
	print(ans)


import math
import bisect
tests = int(input().strip())
while tests:
	tests -= 1
	(n, k) = map(int, input().strip().split())
	array = list(set(map(int, input().strip().split())))
	n = len(array)
	array.sort()
	max_member = array[-1]
	mex = n if max_member == n - 1 else None
	if mex is None:
		for i in range(0, n):
			if array[i] != i:
				mex = i
				break
	if mex == n:
		print(n + k)
	else:
		added = math.ceil((mex + max_member) / 2)
		pos = bisect.bisect_left(array, added)
		if array[pos] == added:
			print(n)
		else:
			print(n + min(1, k))


import sys
input = sys.stdin.readline
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	w = sorted(map(int, input().split()))
	for i in range(n):
		if w[i] != i:
			if ceil((i + max(w)) / 2) in w:
				print(n)
			else:
				print(min(k + n, n + 1))
			break
	else:
		print(n + k)


import sys, math
input = sys.stdin.readline
numOfTests = int(input())

def invr():
	return map(int, input().split())

def getMex(num, maximum, start):
	for i in range(start, maximum):
		if i not in num:
			return i
	return maximum + 1
for _ in range(numOfTests):
	(n, k) = invr()
	nums = list(set(invr()))
	numsLength = len(nums)
	if k == 0:
		print(numsLength)
		continue
	writtenFlag = False
	maxim = max(nums)
	if maxim == numsLength - 1:
		print(numsLength + k)
		continue
	mex = getMex(nums, maxim, 0)
	if mex == maxim + 1:
		print(numsLength + k)
		continue
	for i in range(k):
		toAdd = math.ceil((maxim + mex) / 2)
		if toAdd in nums:
			break
		nums.append(toAdd)
		numsLength += 1
		if toAdd <= maxim and toAdd != mex:
			break
		if toAdd > maxim:
			maxim = toAdd
		if toAdd == mex or mex == maxim + 1:
			print(numsLength + k - i - 1)
			writtenFlag = True
			break
	if not writtenFlag:
		print(numsLength)


def solve(A, n, k):
	setA = set(A)
	ls = len(setA)
	if k == 0:
		return ls
	mexVal = ls
	for i in range(ls):
		if i not in setA:
			mexVal = i
			break
	if mexVal < ls:
		result = ls
		if (mexVal + max(setA) + 1) // 2 not in setA:
			result += 1
	else:
		result = ls + k
	return result
t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	result = solve(A, n, k)
	print(result)


import math

def mex(arr, n):
	for i in range(n):
		if arr[i] != i:
			return i
	return i + 1

def answer(n, k, arr):
	if k == 0:
		return n
	arr.sort()
	m = mex(arr, n)
	M = arr[n - 1]
	if m == M - 1:
		return n
	elif m == M + 1:
		return n + k
	else:
		number = math.ceil((m + M) / 2)
		if number in arr:
			return n
		else:
			return n + 1
t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(answer(n, k, arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	s.sort()
	a = max(s)
	flag = 0
	s = set(s)
	for i in s:
		if i == flag:
			flag += 1
		else:
			break
	if k == 0:
		ans = n
		print(ans)
	elif flag > a:
		ans = n + k
		print(ans)
	else:
		s.add((flag + a + 1) // 2)
		print(len(s))


def mex(a):
	i = 0
	while i in a:
		i += 1
	return i
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = set((int(j) for j in input().split()))
	a = mex(ar)
	b = max(ar)
	c = ceil((a + b) / 2)
	if a == n:
		print(n + k)
	elif k != 0:
		if c in ar:
			print(n)
		else:
			print(n + 1)
	else:
		print(n)


from bisect import bisect_left
from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, k) = map(int, input().split())
	aa = [int(a) for a in input().split()]
	if k == 0:
		print(n)
		return
	aa.sort()

	def mexf(aa):
		if aa[0] != 0:
			return 0
		else:
			c = aa[0]
			for a in aa[1:]:
				if a != c + 1:
					return c + 1
				c += 1
			return c + 1
	mx = aa[-1]
	mex = mexf(aa)
	if mex > mx:
		print(n + k)
		return
	new = (mex + mx + 1) // 2
	p = bisect_left(aa, new)
	if aa[p] == new:
		print(n)
	else:
		print(n + 1)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
import math
for _ in range(t):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	s = set(s)
	b = max(s)
	for i in range(b + 2):
		if i not in s:
			a = i
			break
	if a > b:
		print(len(s) + k)
	elif math.ceil((a + b) / 2) not in s:
		print(len(s) + min(1, k))
	else:
		print(len(s))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	mex = 0
	while mex in a:
		mex = mex + 1
	if k == 0:
		print(n)
	elif mex != n:
		x = math.ceil((mex + max(a)) / 2)
		ans = n
		if x not in a:
			ans = ans + 1
		print(ans)
	elif mex == n:
		ans = n + k
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	st = set(map(int, input().split()))
	a = 0
	if k:
		while a in st:
			a += 1
		b = max(st)
		tmp = (a + b + 1) // 2
		if tmp != a:
			st.add(tmp)
			k = 0
	print(len(st) + k)


import math

def mexMax(n, k, array):
	s = set(array)
	m = len(s)
	for x in range(m + 1):
		if x not in s:
			mex = x
			break
	maxi = max(s)
	if mex < maxi and k > 0:
		s.add(math.ceil((mex + maxi) / 2))
		return len(s)
	else:
		return len(s) + k
t = int(input())
final = []
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	final.append(mexMax(n, k, l))
for _ in range(t):
	print(final[_])


import sys
from itertools import accumulate
import os
from io import BytesIO, IOBase
from math import ceil
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')
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	seq = list(range(n))
	if arr == seq:
		print(n + k)
		continue
	(mex, max_) = (None, arr[-1])
	for i in range(n):
		if arr[i] != i:
			mex = i
			break
	if mex is None:
		mex = n
	arr = set(arr)
	go = min(10, k)
	for _ in range(go):
		val = ceil((mex + max_) / 2)
		arr.add(val)
		max_ = max(arr)
	print(len(arr))


def mex(l):
	s = set(l)
	z = 0
	for i in range(max(l) + 2):
		if i not in s:
			z = i
			break
	return z
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	s = set(l)
	if mex(l) == max(l) + 1:
		print(a + b)
		continue
	if b > 0:
		s.add((max(l) + mex(l) + 1) // 2)
	print(len(s))


import sys
from math import ceil

def find_mex(nums, start):
	while start in nums:
		start += 1
	return start

def perform(length, nums, k):
	if k == 0:
		return length
	max_ = max(nums)
	if max_ == length - 1:
		return length + k
	mex_ = find_mex(nums, 0)
	new_elem = ceil((mex_ + max_) / 2)
	nums.add(new_elem)
	return len(nums)
n = int(sys.stdin.readline().strip())
ans = 0
for i in range(n):
	line = sys.stdin.readline().strip()
	values = list(map(int, line.split()))
	(n, k) = values
	line = sys.stdin.readline().strip()
	multi_set = set(map(int, line.split()))
	res = perform(len(multi_set), multi_set, k)
	print(res)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = set(l)
	if k == 0:
		print(len(s))
		continue
	for i in range(0, n + 1):
		if i not in s:
			mex = i
			break
	max1 = max(s)
	if mex > max1:
		print(len(s) + k)
	else:
		s.add(math.ceil((max1 + mex) / 2))
		print(len(s))


R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'n,k=R();a={*R()};i=0\nwhile{i}&a:i+=1\nprint(n+(k>0)*(k,i+max(a)+1>>1not in a)[i<n])\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	setArr = list(set(arr))
	if k == 0:
		print(len(setArr))
		continue
	setArr.sort()
	f = 1
	mex = -1
	for i in range(len(setArr)):
		if setArr[i] == i:
			pass
		else:
			f = 0
			mex = i
			break
	from math import ceil
	if f == 1:
		print(len(setArr) + k)
	elif ceil((setArr[-1] + mex) / 2) in setArr:
		print(len(setArr))
	else:
		print(len(setArr) + 1)


def mex(check):
	x = 0
	while x in check:
		x += 1
	return x
t = int(input())
otv = []
for p in range(t):
	(n, k) = map(int, input().split())
	mass = set(list(map(int, input().split())))
	if k == 0:
		otv.append(n)
		continue
	else:
		b = max(mass)
		a = mex(mass)
		addition = (a + b + 1) // 2
		if addition > b:
			otv.append(n + k)
		else:
			mass.add(addition)
			otv.append(len(mass))
for j in otv:
	print(j)


def rUp(a):
	if int(a) == a:
		return a
	return int(a) + 1

def mex(s):
	a = 0
	while True:
		if a in s:
			a += 1
		else:
			return a
t = int(input())
for _ in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	mset = set(map(int, input().split()))
	if k == 0:
		print(n)
		continue
	M = max(mset)
	m = mex(mset)
	if m > M:
		print(n + k)
		continue
	if rUp((M + m) / 2) in mset:
		pass
	else:
		n += 1
	print(n)


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s1 = set((int(x) for x in input().split()))
	s1 = sorted(s1)
	flag = 0
	for (id, val) in enumerate(s1):
		if id != val:
			flag = 1
			break
	mex = id if flag == 1 else id + 1
	maxs = max(s1)
	term = ceil((maxs + mex) / 2)
	if term <= maxs:
		if term in s1 or k == 0:
			print(len(s1))
		else:
			print(len(s1) + 1)
	else:
		print(len(s1) + k)


def mex(s, mi, mx):
	if len(s) == mx + 1:
		return mx + 1
	for i in range(mi, mx + 2):
		if i not in s:
			return i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = set(map(int, input().split()))
	mx = max(s)
	mex_v = mex(s, 0, mx)
	flag = 0
	while k > 0:
		k -= 1
		alp = (mex_v + mx + 1) // 2
		s.add(alp)
		if alp <= mx and alp > mex_v:
			break
		elif mex_v == mx + 1:
			flag = 1
			print(len(s) + k)
			break
		else:
			if alp > mx:
				mx = alp
			mex_v = mex(s, mex_v, mx)
	if flag == 0:
		print(len(s))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	c = len(l)
	m = max(l)
	p = -1
	if k == 0:
		print(c)
		continue
	for i in range(m + 1):
		if i not in l:
			p = i
			break
	if p == -1:
		print(c + k)
	else:
		x = p + m
		y = 0
		if x % 2 != 0:
			y = x // 2 + 1
		else:
			y = x // 2
		if y not in l:
			print(c + 1)
		else:
			print(c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 0:
		print(n)
	else:
		arr.sort()
		mex = -1
		max = arr[-1]
		for i in range(n):
			if i != arr[i]:
				mex = i
				break
		if mex == -1:
			print(n + k)
		else:
			ans = n
			while k:
				new = (mex + max) / 2
				if new != int(new):
					new = int(new) + 1
				else:
					new = int(new)
				if new in arr:
					break
				else:
					arr.append(new)
					ans += 1
			print(ans)


import math

def mex(a):
	for i in range(len(a) + 1):
		if i not in a:
			return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	if mex(a) > max(a):
		print(n + k)
		continue
	elif k > 0:
		a.add(math.ceil((max(a) + mex(a)) / 2))
	print(len(a))


import math
import itertools as it
x = int(input())
for i in range(x):
	(n, k) = map(int, input().split())
	s = [int(s) for s in input().split()]
	if k > 0:
		myset = set(s)
		minn = next((i for i in it.count() if i not in myset))
		if minn > max(s):
			print(n + k)
		elif max(s) - minn > 1:
			if math.ceil((max(s) + minn) / 2) not in s:
				print(n + 1)
			else:
				print(n)
		else:
			print(n)
	else:
		print(n)


class Solution:

	def __init__(self):
		pass

	def findMEX(self, S):
		N = len(S)
		newArr = sorted([ele for ele in S if ele < N])
		n = len(newArr)
		for i in range(n):
			if newArr[i] != i:
				return i
		return n

	def distictElementAfterK(self, S, k):
		if k == 0:
			return len(S)
		(mex, maxi, ans) = (self.findMEX(S), max(S), len(S))
		if mex > maxi:
			ans += k
		else:
			newEle = round((mex + maxi) / 2 + 0.01)
			if newEle not in S:
				ans += 1
		return ans
t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	S = set(map(int, input().split(' ')))
	s = Solution()
	print(s.distictElementAfterK(S, k))
	t -= 1


t = int(input())
for _i in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	a.sort()
	minA = 0
	for i in a:
		if minA == i:
			minA += 1
		else:
			break
	maxA = max(a)
	a = set(a)
	if minA == maxA + 1:
		print(k + len(a))
	else:
		if k > 0:
			a.add((minA + maxA + 1) // 2)
		print(len(a))


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
from math import log10, log2, ceil, factorial as f, gcd
for _ in range(t()):
	(n, k) = ll()
	a = list(ll())
	s = sorted(set(a))
	flag = -1
	x = max(s)
	for i in range(len(s)):
		if s[i] != i:
			flag = i
			break
	if flag == -1:
		print(len(s) + k)
	elif k > 0 and ceil((x + flag) / 2) not in s:
		print(len(s) + 1)
	else:
		print(len(s))


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	ans = len(set(s))
	if not k:
		print(ans)
		continue
	s.sort()
	s_max = s[-1]
	s_mex = n
	for i in range(n):
		if i != s[i]:
			s_mex = i
			break
	if s_mex > s_max:
		ans += k
	elif math.ceil((s_max + s_mex) / 2) not in s:
		ans += 1
	print(ans)


import math
t = int(input())
for i in range(t):
	l = list(map(int, input().rstrip().split()))
	n = l[0]
	k = l[1]
	l1 = list(map(int, input().rstrip().split()))
	l1.sort()
	count = 0
	c = 0
	for m in range(len(l1)):
		if l1[m] == m:
			count += 1
			if count == len(l1):
				print(n + k)
		else:
			a = max(l1)
			for x in range(0, a + 2):
				if l1.count(x) == 0:
					b = x
					break
			for j in range(k):
				a = max(l1)
				if math.ceil((a + b) / 2) != c:
					c = math.ceil((a + b) / 2)
					l1.append(c)
				else:
					break
			s = set(l1)
			print(len(s))
			break


def mex(arr):
	s = set(arr)
	z = 0
	for i in range(max(arr) + 2):
		if i not in s:
			z = i
			break
	return z
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = set(arr)
	if mex(arr) == max(arr) + 1:
		print(n + k)
		continue
	if k > 0:
		s.add((max(arr) + mex(arr) + 1) // 2)
	print(len(s))


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import *
from statistics import *
from math import *
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange
from time import time

def ncr(n, r, p=mod):
	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 normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

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

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]

def p(a):
	if type(a) == str:
		print(a + '\n')
	else:
		print(str(a) + '\n')

def ps(a):
	if type(a) == str:
		print(a)
	else:
		print(str(a))

def kth_no_not_div_by_n(n, k):
	return k + (k - 1) // (n - 1)

def forward_array(l):
	n = len(l)
	stack = []
	forward = [0] * n
	for i in range(len(l) - 1, -1, -1):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			forward[i] = len(l)
		else:
			forward[i] = stack[-1]
		stack.append(i)
	return forward

def backward_array(l):
	n = len(l)
	stack = []
	backward = [0] * n
	for i in range(len(l)):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			backward[i] = -1
		else:
			backward[i] = stack[-1]
		stack.append(i)
	return backward
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'

def mexa(l):
	s = set(l)
	for i in range(len(l) + 1):
		if i not in s:
			return i

def all_pre(l):
	s = set(l)
	for i in range(len(l) + 1):
		if i not in s:
			break
	if i == len(l):
		return 1
	return 0
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if k == 0:
		print(n)
		continue
	pre_mex = mexa(l)
	pre_max = max(l)
	if pre_mex > pre_max:
		print(n + k)
		continue
	adder = pre_max + pre_mex
	adder = ceil(adder / 2)
	if adder in l:
		print(n)
	else:
		print(n + 1)


def main():
	import math
	ans = []
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort()
		if k == 0:
			ans.append(n)
		elif a[-1] == n - 1:
			ans.append(n + k)
		else:
			mex = 0
			for x in a:
				if x == mex:
					mex += 1
				else:
					break
			s = set(a)
			x = math.ceil((mex + a[-1]) / 2)
			if x in s:
				ans.append(n)
			else:
				ans.append(n + 1)
	print('\n'.join(map(str, ans)))
main()


import sys, os.path
import math
import collections

def findMex(arr):
	for i in range(len(arr)):
		if arr[i] != i:
			return i
	return arr[-1] + 1

def solve():
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	if k == 0:
		print(n)
		return
	arr.sort()
	mexV = findMex(arr)
	maxV = arr[-1]
	if mexV == maxV + 1:
		print(n + k)
	else:
		print(n + (1 if math.ceil((maxV + mexV) / 2) not in arr else 0))
if os.path.exists('input_file.txt'):
	sys.stdin = open('input_file.txt', 'r')
	sys.stdout = open('output_file.txt', 'w')
n = 1
n = int(input())
for _ in range(n):
	solve()


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	nums = set(map(int, input().split()))
	mexn = 0
	while mexn in nums:
		mexn += 1
	maxn = max(nums)
	if mexn > maxn or k == 0:
		print(n + k)
	else:
		print(n if math.ceil((mexn + maxn) / 2) in nums else n + 1)


import math

def max_mex(num):
	main_set = set(num)
	check_set = set([x for x in range(n)])
	a = check_set.difference(main_set)
	b = max(num)
	return math.ceil((a + b) / 2)
test_case = int(input())
for i in range(test_case):
	(n, k) = [int(x) for x in input().split()]
	num = [int(x) for x in input().split()]
	main_set = set(num)
	check_set = set([x for x in range(len(main_set))])
	a = check_set.difference(main_set)
	b = max(num)
	if k == 0:
		print(len(main_set))
	elif a == set():
		print(len(main_set) + k)
	else:
		a = min(a)
		new_num = math.ceil((a + b) / 2)
		if new_num in num:
			print(len(main_set))
		else:
			print(len(main_set) + 1)


import math

def get_mex(sett, last):
	for i in range(last, 10 ** 9 + 1):
		if i not in sett:
			return i

def solve(A, k):
	sett = set()
	for a in A:
		sett.add(a)
	mexx = get_mex(sett, 0)
	maxx = max(A)
	for i in range(k):
		if maxx + 1 == mexx:
			return len(sett) + (k - i)
		next = math.ceil((mexx + maxx) / 2)
		if next in sett:
			return len(sett)
		else:
			sett.add(next)
			mexx = get_mex(sett, mexx)
	return len(sett)
x = int(input())
for _ in range(x):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	print(solve(B, A[1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	if a[-1] - a[0] + 1 == n and a[0] == 0:
		print(n + k)
	else:
		if k == 0:
			print(n)
			continue
		j = 0
		for i in range(n):
			if a[i] != j:
				mes = j
				break
			j += 1
		if (a[-1] + mes + 1) // 2 in a:
			print(n)
		else:
			print(n + 1)


import math

def mex(S, i):
	while i in S:
		i += 1
	return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	S = set(map(int, input().split()))
	a = mex(S, 0)
	b = max(S)
	if a == len(S):
		print(n + k)
	else:
		if k > 0:
			S.add(int(math.ceil((a + b) / 2)))
		print(len(S))


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	num_list = list(map(int, input().split()))
	num_list.sort()
	MAX = num_list[-1]
	i = 0
	if k:
		for _ in num_list:
			if _ == i:
				pass
			else:
				MEX = i
				break
			i += 1
		if i == len(num_list):
			MEX = num_list[-1] + 1
		if MEX < MAX:
			num_list.append(ceil((MEX + MAX) / 2))
			print(len(set(num_list)))
		elif MEX > MAX:
			print(len(num_list) + k)
	else:
		print(len(num_list))


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	S = set(A)
	if A == list(range(n)):
		print(n + k)
		continue
	for (i, a) in enumerate(A):
		if i != a:
			mex = i
			break
	M = max(A)
	if k > 0:
		x = (mex + M + 1) // 2
		if x in S:
			print(len(S))
		else:
			print(len(S) + 1)
	else:
		print(len(S))


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

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

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

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

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

def Solution(arr, n, k):
	mp = {}
	uniq = 0
	mx = max(arr)
	for v in arr:
		if v in mp:
			mp[v] += 1
		else:
			mp[v] = 1
		if mp[v] == 1:
			uniq += 1
	me = float('inf')
	for i in range(mx + 1):
		if not i in mp:
			me = i
			break
	if me < mx and k != 0:
		avg = math.ceil((me + mx) / 2)
		if avg in mp:
			mp[avg] += 1
		else:
			mp[avg] = 1
		if mp[avg] == 1:
			uniq += 1
	elif me > mx and k != 0:
		uniq += k
	print(uniq)

def main():
	for _ in range(get_int()):
		(n, k) = get_ints_in_variables()
		arr = get_ints_in_list()
		Solution(arr, n, k)
main()


t = int(input())
for i in range(0, t):
	f = input()
	array = f.split(' ')
	n = int(array[0])
	k = int(array[1])
	s = input()
	s = list(map(int, s.split(' ')))
	ss = set(s)
	for j in range(n + 1):
		if j not in ss:
			break
	MAX = max(ss)
	e = -(-(j + MAX) // 2)
	if len(ss) == MAX + 1:
		print(len(ss) + k)
	elif k >= 1 and e not in ss:
		print(len(ss) + 1)
	else:
		print(len(ss))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	a = lis()
	a.sort()
	p = 0
	for i in range(n):
		if a[i] == p:
			p += 1
		else:
			break
	if p == n:
		print(n + k)
		continue
	else:
		add = p + a[-1]
		add = (add - 1) // 2 + 1
		if add in a:
			print(n)
		elif k:
			print(n + 1)
		else:
			print(n)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	if k == 0:
		print(len(l))
	else:
		for i in range(n):
			if i not in l:
				mex = i
				break
		else:
			mex = n
		if mex != n:
			if ceil((mex + max(l)) / 2) not in l:
				print(len(l) + 1)
			else:
				print(len(l))
		else:
			print(len(l) + k)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	setA = set(A)
	ma_x = max(A)
	flag = 0
	if k == 0:
		print(n)
		continue
	for i in range(0, 999999999):
		if i not in setA:
			mex = i
			break
	if mex > ma_x:
		print(n + k)
	else:
		p = mex + ma_x
		if p % 2 != 0:
			p = p / 2 * 10
			if p % 10 >= 5:
				p = int(p // 10) + 1
			else:
				p = int(p // 10)
		else:
			p = p // 2
		if p not in setA:
			print(n + 1)
		else:
			print(n)


T = int(input())
r = 1
while r <= T:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	mex = 0
	maximum = 0
	for i in range(n):
		dic[arr[i]] = 1
		maximum = max(arr[i], maximum)
	while mex in dic:
		mex += 1
	if k == 0:
		print(len(dic))
	else:
		nextone = (mex + maximum + 1) // 2
		if nextone in dic:
			print(len(dic))
		elif mex > maximum:
			print(len(dic) + k)
		else:
			print(len(dic) + 1)
	r += 1


from sys import stdin, stdout
from collections import Counter, OrderedDict, defaultdict
import math
import re
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')

def binSearch(l, val, start, end):
	if end < start:
		return False
	mid = (start + end) // 2
	if l[mid] == val:
		return True
	elif l[mid] < val:
		return binSearch(l, val, mid + 1, end)
	elif l[mid] > val:
		return binSearch(l, val, start, mid - 1)

def myLog(x, y):
	z = int(math.log(x, y))
	if y ** (z + 1) > x:
		return z
	elif y ** (z + 1) == x:
		return z + 1
(t,) = mp()
for _ in range(t):
	(n, k) = mp()
	a = set(mp())
	a = sorted(list(a))
	x = 0
	for i in range(len(a)):
		if i != a[i]:
			x = i
			break
	else:
		x = max(a) + 1
	if not k:
		cout(str(len(a)) + '\n')
	elif max(a) + 1 == x:
		cout(str(len(a) + k) + '\n')
	else:
		a += [math.ceil((x + max(a)) / 2)]
		a = set(a)
		cout(str(len(a)) + '\n')


import sys
from sys import stdin
import math

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

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

def fiinput():
	return int(stdin.readline())

def fminput():
	return map(int, stdin.readline().strip().split())

def flinput():
	return list(map(int, stdin.readline().strip().split()))
c = 0
for _ in range(iinput()):
	(n, k) = minput()
	list1 = linput()
	m = max(list1)
	set1 = set(list1)
	f = 0
	if k != 0:
		list1.sort()
		x = 0
		for i in range(len(list1)):
			if list1[i] == x:
				x += 1
			elif list1[i] > x:
				f = 1
				ff = x
		if f == 1:
			set1.add(math.ceil((m + ff) / 2))
			print(len(set1))
		else:
			print(len(set1) + k)
	else:
		print(len(set1))


import math
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	s = set(map(int, input().split()))
	a = -1
	a = max(s)
	p = 0
	b = 0
	while b in s:
		b = b + 1
	ans = math.ceil((a + b) / 2)
	if k > 0:
		if a > b:
			if ans in s:
				print(n)
			else:
				print(n + 1)
		else:
			print(n + k)
	else:
		print(n)


from math import ceil

def find_mex(arr):
	mex = 0
	while True:
		if mex not in arr:
			return mex
		mex += 1

def find_max(arr):
	return max(arr)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = set(map(int, input().split()))
	a = find_max(lst)
	b = find_mex(lst)
	if b > a:
		print(len(lst) + k)
	elif k == 0:
		print(len(lst))
	else:
		ans = ceil((a + b) / 2)
		if ans in lst:
			print(len(lst))
		else:
			print(len(lst) + 1)


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

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

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, k) = get_ints()
	store = set()
	a = get_array()
	mx = -1
	for i in a:
		store.add(i)
		mx = max(mx, i)
	mex = -1
	for i in range(mx + 5):
		if i not in store:
			mex = i
			break
	x = math.ceil((mx + mex) / 2)
	if k == 0:
		print(n)
	elif mex > mx:
		print(n + k)
	elif x in store:
		print(n)
	else:
		print(n + 1)


from math import ceil
for tc in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	book = {}
	initlena = len(a)
	for i in a:
		if i not in book:
			book[i] = 1
	me = 0
	cnt = 0
	flag = 1
	ma = max(a)

	def mex(a):
		global me
		while me in book:
			me += 1
		return me
	while k > 0:
		m1 = mex(a)
		m2 = max(a)
		t = ceil((m1 + m2) / 2)
		if t in a:
			print(len(set(a)))
			flag = 0
			break
		if m1 == m2 + 1:
			print(m2 + k - cnt + 1)
			flag = 0
			break
		a.append(t)
		book[t] = 1
		cnt += 1
	if flag:
		print(len(set(a)))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = set(map(int, input().split()))
	b = 0
	maxi = max(arr)
	for i in range(maxi + 1):
		if i not in arr:
			b = i
			break
	if len(arr) == maxi + 1:
		print(len(arr) + k)
	elif k >= 1:
		arr.add((b + maxi + 1) // 2)
		print(len(arr))
	else:
		print(len(arr))


import math
t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	l = set([int(x) for x in input().split()])
	ma = max(l)
	me = ma
	c = n
	for i in range(ma):
		if i not in l:
			me = i
			break
	if me == ma or k == 0:
		c = c + k
	else:
		x = math.ceil((ma + me) / 2)
		if x not in l:
			c = c + 1
	print(c)
	t = t - 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	mex = 0
	for i in range(n + 1):
		if i not in s:
			mex = i
			break
	l = len(s)
	m = max(a)
	b = (mex + m + 1) // 2
	if k == 0:
		print(l)
		continue
	if mex > m:
		print(l + k)
	else:
		if b not in s:
			l += 1
		print(l)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 0:
		print(len(set(a)))
	elif sorted(a) == [i for i in range(n)]:
		print(n + k)
	else:
		b = ceil((sorted(list(set([i for i in range(n)]) - set(a)))[0] + max(a)) / 2)
		if b in a:
			print(len(set(a)))
		else:
			print(len(set(a)) + 1)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	Mex = -1
	if arr[0] != 0:
		Mex = 0
	else:
		for i in range(n - 1):
			if arr[i] != arr[i + 1] and arr[i] + 1 != arr[i + 1]:
				Mex = arr[i] + 1
				break
		else:
			Mex = arr[-1] + 1
	Max = arr[-1]
	S = set(arr)
	ans = len(S)
	if k > 0:
		if Max > Mex:
			S.add(ceil((Max + Mex) / 2))
			ans = len(S)
		elif Max < Mex:
			assert Mex == Max + 1
			ans += k
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()

def sol():
	if ls[0] == 0 and ls[-1] + 1 == n:
		return ls[-1] + k + 1
	max_ = ls[-1]
	prev = ls[0]
	if ls[0] != 0:
		mex_ = 0
	else:
		for idx in range(1, n):
			if ls[idx] == prev + 1:
				prev = ls[idx]
			else:
				mex_ = prev + 1
	S = set(ls)
	if k > 0:
		S.add((max_ + mex_ + 1) // 2)
		return len(S)
	else:
		return len(S)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	ls.sort()
	print(sol())


t = int(input())

def mex(seq: set):
	res = 0
	while res in seq:
		res += 1
	return res
while t:
	inp = input().strip().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	seq = [int(i) for i in input().strip().split(' ')]
	distinct = set(seq)
	ma = max(seq)
	me = mex(distinct)
	res = len(distinct)
	if k == 0:
		pass
	elif ma == me - 1:
		res += k
	elif (ma + me) // 2 + (ma + me) % 2 not in distinct:
		res += 1
	print(res)
	t -= 1


from math import ceil

def mex(se):
	me = max(se)
	check_for = 0
	while True:
		if check_for not in se:
			return check_for
		check_for += 1
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	v = set(map(int, input().split()))
	if mex(v) > max(v):
		print(len(v) + k)
	elif k == 0:
		print(len(v))
	else:
		mx = max(v)
		mi = mex(v)
		addd = ceil((mx + mi) / 2)
		if addd not in v:
			print(len(v) + 1)
		else:
			print(len(v))


import sys
import bisect
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7

def hnbhai():
	(n, k) = sd()
	a = sd()
	a.sort()
	if k == 0:
		print(n)
		return
	mx = max(a)
	x = 0
	for i in range(n):
		if x < a[i]:
			break
		else:
			x = a[i] + 1
	if x < mx:
		y = -(-(mx + x) // 2)
		if y in a:
			print(n)
			return
		print(n + 1)
	else:
		print(n + k)
for _ in range(sb()):
	hnbhai()


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split(' ')))
	S = list(set(list(map(int, input().split(' ')))))
	S.sort()
	elems = len(S)
	maxl = max(S)
	mexl = -1
	if k == 0:
		print(elems)
		continue
	for i in range(elems):
		if S[i] != i:
			mexl = i
			break
	if mexl == -1:
		print(elems + k)
	elif (maxl + mexl + 1) // 2 in S:
		print(elems)
	else:
		print(elems + 1)


n = int(input())
for i1 in range(n):
	seq = input()
	A1 = seq.split()
	length = int(A1[0])
	k = int(A1[1])
	seq = input()
	if k == 0:
		print(length)
		continue
	A2 = seq.split()
	A2 = [int(x) for x in A2]
	b = max(A2)
	if b == length - 1:
		print(length + k)
		continue
	count = 0
	for i2 in A2:
		if count not in A2:
			mex = count
			break
		count += 1
	S = round((mex + b) / 2 + 0.01)
	if S not in A2:
		print(length + 1)
	else:
		print(length)


import math

def maxAndMex(s, k):
	if k == 0:
		return len(s)
	if sum(s) == len(s) * (len(s) - 1) // 2:
		return k + len(s)
	i = 0
	while True:
		if i not in s:
			break
		i += 1
	if math.ceil((max(s) + i) / 2) in s:
		return len(s)
	else:
		return len(s) + 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = set(map(int, input().split()))
	print(maxAndMex(s, k))


from math import ceil
for t in range(int(input())):
	(n, k) = map(int, input().split())
	s = set([int(x) for x in input().split()])
	for num in range(n):
		if num not in s:
			mex = num
			break
	else:
		mex = n + 1
	if mex < n + 1:
		if k > 0:
			s.add(ceil((max(s) + mex) / 2))
		print(len(s))
	else:
		print(n + k)


import bisect
sr = lambda : input()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	(n, k) = lr()
	s = lr()
	if k == 0:
		print(len(s))
		continue
	s.sort()
	flg = True
	mex_s = 0
	max_s = max(s)
	for i in range(n):
		if i != s[i]:
			flg = False
			mex_s = i
			break
	if flg:
		print(len(s) + k)
	else:
		tmp = (max_s + mex_s + 1) // 2
		if s[bisect.bisect_left(s, tmp)] == tmp:
			print(len(s))
		else:
			print(len(s) + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	if k == 0:
		print(n)
		continue
	mex = 0
	nums.sort()
	count = 0
	for i in nums:
		if i != count:
			mex = count
			break
		count += 1
	else:
		print(n + k)
		continue
	b = nums[-1]
	opt = (mex + b) // 2 if (mex + b) % 2 == 0 else (mex + b) // 2 + 1
	if opt in nums:
		print(n)
	else:
		print(n + 1)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	answer = len(a)
	a_max = max(a)
	if len(a) < a_max + 1:
		a_mex = a_max + 1
		for i in range(a_max):
			if i not in a:
				a_mex = i
				break
		if ceil((a_mex + a_max) / 2) not in a and k != 0:
			answer += 1
	else:
		answer += k
	print(answer)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

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

def main():
	for _ in range(int(input())):
		(n, k) = get_ints()
		ls = get_ls()
		st = set(ls)
		ax = max(ls)
		ex = 0
		for i in range(ax + 2):
			if i not in st:
				ex = i
				break
		if ex == ax + 1:
			print(n + k)
			continue
		if k > 0:
			st.add((ax + ex + 1) // 2)
		print(len(st))
main()


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial, sqrt
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, accumulate
from bisect import *
from functools import reduce
from operator import mul
star = lambda x: print(' '.join(map(str, x)))
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
INF = float('inf')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import sys
from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, stdin.readline().split())

def pr(n):
	return stdout.write(str(n) + '\n')

def find_mex(arr, n):
	mex = -1
	for i in range(n):
		if arr[i] != i:
			return i
	return mex

def solve():
	(n, k) = invr()
	arr = inlt()
	arr.sort()
	res = 0
	missing_val = find_mex(arr, n)
	b = max(arr)
	if missing_val == -1 or k == 0:
		print(n + k)
	else:
		res = ceil((max(arr) + missing_val) / 2)
		arr.append(res)
		print(len(set(arr)))
t = 1
t = inp()
for _ in range(t):
	solve()


from sys import stdin, stdout

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

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

def read_int_tuple():
	return tuple(map(int, input().split()))

def read_int():
	return int(input())

def cdiv(x, y):
	return x // y if x % y == 0 else x // y + 1

def mex(A):
	sA = set(A)
	for i in range(0, max(A) + 10):
		if i not in sA:
			return i

def ans(K, S):
	S = set(S)
	a = mex(S)
	b = max(S)
	if a == b + 1:
		return len(S) + K
	if K > 0:
		S.add(cdiv(a + b, 2))
	return len(S)

def ans_slow(K, S):
	S = set(S)
	for _ in range(K):
		a = mex(S)
		b = max(S)
		S.add(cdiv(a + b, 2))
	return len(S)
for _ in range(read_int()):
	(_, K) = read_int_tuple()
	S = read_int_list()
	print(ans(K, S))


import sys
from math import ceil as c

def mex(s, max):
	res = 0
	for i in range(max):
		if i not in s:
			return i
for _ in range(int(input())):
	(n, k) = map(int, sys.stdin.readline().split())
	s = set(map(int, sys.stdin.readline().split()))
	m = max(s)
	if m == n - 1:
		print(n + k)
	else:
		for i in range(k):
			new = c((mex(s, m) + m) / 2)
			if new in s:
				break
			else:
				s.add(new)
		print(len(s))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = set(map(int, input().split()))
	a = 0
	while a in b:
		a += 1
	mx = max(b)
	if k == 0:
		print(len(b))
	elif a > mx:
		print(len(b) + k)
	else:
		b.add((a + mx + 1) // 2)
		print(len(b))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	l = []
	for j in range(n):
		if j not in a:
			l.append(j)
	l.append(n + 1)
	if k == 0:
		print(n)
	elif l[0] != n + 1:
		x = math.ceil((l[0] + max(a)) / 2)
		ans = n
		if x not in a:
			ans = ans + 1
		print(ans)
	elif l[0] == n + 1:
		ans = n + k
		print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	mex_val = 0
	max_val = l[-1]
	while True:
		if mex_val < n and l[mex_val] == mex_val:
			mex_val += 1
			continue
		else:
			new_val = math.ceil((mex_val + max_val) / 2)
			if k == 0 or new_val in l:
				print(n)
			elif mex_val > max_val:
				print(n + k)
			else:
				print(n + 1)
			break


from sys import stdin, stdout
input = stdin.readline

def mex(arr):
	for i in range(0, 100000000):
		if i not in arr:
			return i

def ceil(a, b):
	return (a + b - 1) // 2
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr)
	vals = [i for i in range(0, n)]
	if arr == vals:
		print(n + k)
		continue
	arr = set(arr)
	for i in range(min(k, 10)):
		val = ceil(mex(arr) + max(arr), 2)
		arr.add(val)
	print(len(arr))


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	a.sort()
	if a[-1] == n - 1:
		print(n + k)
		continue
	mex = -1
	for i in range(n):
		if a[i] != i:
			mex = i
			break
	assert mex + 1
	newel = max(a) + mex
	if newel % 2:
		newel += 1
	newel = round(newel / 2)
	if a.count(newel):
		print(n)
	elif k:
		print(n + 1)
	else:
		print(n)


from math import ceil
t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	a.sort()
	if k == 0:
		print(n)
	else:
		if a[0] != 0:
			x = 0
		else:
			x = 0
			for i in range(1, n):
				if a[i] - a[i - 1] > 1:
					x = a[i - 1] + 1
					break
			if x == 0:
				x = a[-1] + 1
		v = n
		if x == 0:
			if ceil((x + a[-1]) / 2) not in a:
				v += 1
		elif x == a[-1] + 1:
			v += k
		elif ceil((x + a[-1]) / 2) not in a:
			v += 1
		print(v)


import math

def check(lis):
	i = 0
	while True:
		if i not in lis:
			return i
		i += 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = set(map(int, input().split()))
	mex = check(lis)
	if k == 0 or mex > max(lis):
		d = set(lis)
		print(len(d) + k)
	elif math.ceil((mex + max(lis)) / 2) in lis:
		print(n)
	else:
		print(n + 1)


import math
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	l = [0 for i in range(0, n)]
	maxx = -1
	for j in range(n):
		if a[j] < n:
			l[a[j]] = 1
		d[a[j]] = 1
		maxx = max(maxx, a[j])
	mex = -1
	for i in range(n):
		if l[i] == 0:
			mex = i
			break
	if mex == -1:
		mex = n + 1
	div = math.ceil((mex + maxx) / 2)
	if k == 0:
		print(n)
	elif mex > maxx:
		print(n + k)
	elif div in d:
		print(n)
	else:
		print(n + 1)


def mex(a):
	x = 0
	while x in a:
		x += 1
	return x
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == 0:
		a = input()
		print(n)
	else:
		a = set([int(x) for x in input().split()])
		m = max(a)
		me = mex(a)
		if me > m:
			print(n + k)
		else:
			a.add((me + m + 1) // 2)
			print(len(a))