You are given a non-decreasing array of non-negative integers $a_1, a_2, \ldots, a_n$. Also you are given a positive integer $k$.

You want to find $m$ non-decreasing arrays of non-negative integers $b_1, b_2, \ldots, b_m$, such that:  The size of $b_i$ is equal to $n$ for all $1 \leq i \leq m$.  For all $1 \leq j \leq n$, $a_j = b_{1, j} + b_{2, j} + \ldots + b_{m, j}$. In the other word, array $a$ is the sum of arrays $b_i$.  The number of different elements in the array $b_i$ is at most $k$ for all $1 \leq i \leq m$. 

Find the minimum possible value of $m$, or report that there is no possible $m$.


-----Input-----

The first line contains one integer $t$ ($1 \leq t \leq 100$): the number of test cases.

The first line of each test case contains two integers $n$, $k$ ($1 \leq n \leq 100$, $1 \leq k \leq n$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_1 \leq a_2 \leq \ldots \leq a_n \leq 100$, $a_n > 0$).


-----Output-----

For each test case print a single integer: the minimum possible value of $m$. If there is no such $m$, print $-1$.


-----Example-----
Input
6
4 1
0 0 0 1
3 1
3 3 3
11 3
0 1 2 2 3 3 3 4 4 4 4
5 3
1 2 3 4 5
9 4
2 2 3 5 7 11 13 13 17
10 7
0 1 1 2 3 3 4 5 5 6

Output
-1
1
2
2
2
1



-----Note-----

In the first test case, there is no possible $m$, because all elements of all arrays should be equal to $0$. But in this case, it is impossible to get $a_4 = 1$ as the sum of zeros.

In the second test case, we can take $b_1 = [3, 3, 3]$. $1$ is the smallest possible value of $m$.

In the third test case, we can take $b_1 = [0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]$ and $b_2 = [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]$. It's easy to see, that $a_i = b_{1, i} + b_{2, i}$ for all $i$ and the number of different elements in $b_1$ and in $b_2$ is equal to $3$ (so it is at most $3$). It can be proven that $2$ is the smallest possible value of $m$.

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
from collections import Counter
from math import ceil
t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	count = Counter(arr)
	pp = len(count)
	if k >= pp:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(1 + ceil((pp - k) / (k - 1)))
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	s = set(a)
	num = len(s)
	if k == 1 and num > 1:
		print(-1)
	else:
		num -= k
		k -= 1
		count = 1
		while num > 0:
			num -= k
			count += 1
		print(count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	diff = 0
	last = next(a)
	for v in a:
		if last != v:
			diff += 1
		last = v
	if k == 1:
		if diff:
			print(-1)
		else:
			print(1)
	else:
		print(max(1, (diff + k - 2) // (k - 1)))


def solve(A, n, k):
	prev = -1
	dist = []
	for it in A:
		if it != prev:
			dist.append(it)
			prev = it
	td = len(dist)
	if k == 1:
		if td == 1:
			return 1
		else:
			return -1
	if td <= k:
		return 1
	ans = (td - 2) // (k - 1) + 1
	return ans
for case in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = solve(a, n, k)
	print(ans)


import sys

def main():
	T = int(input())
	for ti in range(T):
		(n, k) = map(int, input().split())
		A = set((int(v) for v in input().split()))
		if k == 1:
			if len(A) == 1:
				print(1)
			else:
				print(-1)
			continue
		if len(A) == 1:
			print(1)
		else:
			print((len(A) - 3 + k) // (k - 1))
main()


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	setA = set()
	for i in range(n):
		setA.add(ar[i])
	if k == 1 and len(setA) > 1:
		print(-1)
		continue
	if len(setA) <= k:
		print(1)
		continue
	answer = max(0, math.ceil((len(setA) - k) / (k - 1)) + 1)
	print(answer)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1 and len(set(a)) > 1:
		print(-1)
	else:
		m = 0
		while a != [0] * n:
			k1 = k
			tmp = -1
			for i in range(n):
				if k1 > 0 and a[i] > tmp:
					tmp = a[i]
					a[i] -= tmp
					k1 -= 1
				else:
					a[i] -= tmp
			m += 1
		print(m)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	m = len(s)
	ans = 0
	if k == 1:
		if m == 1:
			print(1)
		else:
			print(-1)
	elif m <= k:
		print(1)
	else:
		ans = 1
		p = ceil((m - k) / (k - 1))
		ans = ans + p
		print(ans)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

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

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	cnt = 1
	for i in range(1, n):
		if a[i] - a[i - 1] != 0:
			cnt += 1
	if cnt <= k:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(1 + (cnt - k) // (k - 1) + ((cnt - k) % (k - 1) != 0))


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
mod = 10 ** 9 + 7
mod1 = 998244353
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')

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=300006, func=lambda a, b: min(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: max(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

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		s = set(a)
		if len(s) != 1:
			print(-1)
		else:
			print(1)
	else:
		ans = 0
		while sum(a) != 0:
			ans += 1
			cou = 0
			s = set()
			last = 0
			for i in range(n):
				if cou < k:
					if a[i] not in s:
						cou += 1
						s.add(a[i])
					last = a[i]
					a[i] = 0
				elif cou == k and a[i] in s:
					a[i] = 0
				else:
					a[i] -= last
		print(ans)


import sys
from collections import defaultdict
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	c = 0
	res = [0] * n
	while True:
		for i in range(n):
			lis[i] -= res[i]
		s = set()
		for i in range(n):
			if len(s) < k:
				s.add(lis[i])
				res[i] = lis[i]
				m = lis[i]
			else:
				res[i] = m
		c += 1
		if set(lis) == {0}:
			break
		if set(res) == {0}:
			c = 0
			break
	print(c - 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1 and [a[0]] * n != a:
		print(-1)
		continue
	cnt = 0
	while a.count(0) != n:
		cnt += 1
		b = [a[0]]
		for i in range(1, n):
			if a[i] == b[-1]:
				continue
			else:
				b.append(a[i])
		if len(b) < k:
			break
		c = b[k - 1]
		for i in range(n):
			a[i] = max(0, a[i] - c)
	print(cnt)


from collections import Counter

def solve(n, k, a, count):
	if count <= k:
		return 1
	if k == 1:
		if count != 1:
			return -1
		return 1
	c = 0
	m = 0
	l = 0
	s = set()
	for i in range(n):
		if a[i] - l not in s:
			s.add(a[i] - l)
		c += 1
		if len(s) == k or c == n:
			m += 1
			s = set()
			s.add(0)
			l = a[i]
			c = 0
	if len(s) > 1:
		m += 1
	return m
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = Counter(a)
	count = len(p)
	print(solve(n, k, a, count))


a = int(input())
for k in range(0, a):
	b = list(map(int, input().split()))
	h = list(map(int, input().split()))
	if h.count(h[0]) != len(h) and b[1] == 1 and (len(h) > 1):
		print(-1)
	else:
		c = []
		for i in range(0, len(h)):
			if h[i] not in c:
				c.append(h[i])
		i = 0
		while c.count(0) != len(c):
			j = 0
			h = 0
			if c.count(0) != 0:
				h = h + 1
			while h < b[1]:
				if c.count(0) != len(c):
					if c[j] != 0:
						c[j] = 0
						h = h + 1
				else:
					break
				j = j + 1
			j = j - 1
			h = c[j]
			j = j + 1
			while j < len(c):
				c[j] = c[j] - h
				j = j + 1
			i = i + 1
		print(i)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	n = int(temparr[0])
	k = int(temparr[1])
	temparr = input()
	temparr = temparr.split()
	arr = []
	dicts = {}
	for i in temparr:
		arr.append(int(i))
		dicts[i] = 1
	if k == 1 and len(dicts) == 1:
		print(1)
		continue
	elif k == 1 and len(dicts) >= 1:
		print(-1)
		continue
	count = 0
	while sum(arr) != 0:
		curk = 0
		curmax = 0
		dicts = {}
		for i in range(n):
			curelem = arr[i]
			if curelem not in dicts and curk < k:
				curmax = curelem
				dicts[curelem] = 1
				curk += 1
				arr[i] = 0
			elif curelem in dicts:
				arr[i] = 0
			elif curk == k:
				arr[i] -= curmax
		count += 1
	print(count)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(a) for a in input().split()]
	dif_values = len(set(A))
	if k == 1:
		print(1 if dif_values == 1 else -1)
	elif k == dif_values:
		print(1)
	else:
		m = 1
		dif_values -= k
		while dif_values > 0:
			dif_values -= k - 1
			m += 1
		print(m)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
	(N, K) = list(map(int, readline().split()))
	A = list(map(int, readline().split()))
	if K == 1:
		if len(set(A)) == 1:
			Ans[qu] = 1
		else:
			Ans[qu] = -1
	else:
		s = len(set(A))
		if K >= s:
			Ans[qu] = 1
		else:
			Ans[qu] = 1 - (K - s) // (K - 1)
print('\n'.join(map(str, Ans)))


import math

def solve(a, n, k):
	st = set(a)
	if k == 1 and len(st) == 1:
		return 1
	if k == 1 and len(st) != 1:
		return -1
	return max(1, 1 + math.ceil((len(st) - k) / (k - 1)))
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(a, n, k))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	g = [0] * 105
	for j in range(n):
		g[a[j]] = g[a[j]] + 1
	c = 0
	for j in range(105):
		if g[j] > 0:
			c = c + 1
	if c <= k:
		print('1')
	elif k == 1 and c > 1:
		print('-1')
	else:
		if (c - 1) % (k - 1) == 0:
			c = (c - 1) // (k - 1)
		else:
			c = (c - 1) // (k - 1) + 1
		print(c)


import sys

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

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def ceil(x, y=1):
	return int(-(-x // y))
import math
from collections import defaultdict
for _ in range(ri()):
	(n, k) = ria()
	l = ria()
	s = set(l)
	if k == 1 and len(s) > 1:
		wi(-1)
	elif k == 1 and len(s) == 1:
		wi(1)
	else:
		x = len(s)
		if x <= k:
			wi(1)
		else:
			x -= k
			k -= 1
			wi(1 + math.ceil(x / k))


game = int(input())
for i in range(game):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = set(a)
	p = len(b)
	q = 0
	count = 0
	j = 1
	if k == 1:
		if p == 1:
			print(1)
		else:
			print(-1)
	elif p <= k:
		print(1)
	else:
		q = p - k
		while (q - 0.1) // ((k - 1) * j) != 0:
			count += 1
			j += 1
		print(count + 2)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	start = a[0]
	cn = 1
	dsnt = 1
	flag = 1
	for i in a:
		if i != start and k != 1 and (dsnt == k):
			cn += 1
			dsnt = 2
			start = i
		if i != start:
			start = i
			dsnt += 1
		if dsnt > k:
			flag = 0
			break
	if flag == 0:
		stdout.write(str(-1) + '\n')
	else:
		stdout.write(str(cn) + '\n')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	a = len(set(arr)) - 1
	if k == 1:
		if a:
			print(-1)
		else:
			print(1)
	else:
		print(1 + max(0, (a - 1) // (k - 1)))


import math

def numOfDifferentElements(arr):
	list = []
	for i in range(len(arr)):
		if arr[i] not in list:
			list.append(arr[i])
	return len(list)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	difElements = numOfDifferentElements(a)
	if difElements > 1 and k == 1:
		print(-1)
	else:
		ans = 1
		difElements -= k
		if difElements <= 0:
			print(1)
		else:
			ans += math.ceil(difElements / (k - 1))
			print(ans)


for __ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	h = len(set(a))
	count = 0
	if k == 1:
		if h == 1:
			print(1)
		else:
			print(-1)
	else:
		for i in range(0, n - 1):
			if a[i + 1] - a[i] != 0:
				count += 1
		if count == 0:
			print(1)
		elif count % (k - 1) != 0:
			print(count // (k - 1) + 1)
		else:
			print(count // (k - 1))


import sys
import random
from fractions import Fraction
from math import *

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

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

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

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

def trinput():
	return tuple(rinput())

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

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	(n, k) = rinput()
	q = len(set(rlinput()))
	if k == 1:
		print(-1 if q != 1 else 1)
		return 0
	print((k - 2 + max(q - k, 0)) // (k - 1) + 1)
for i in range(iinput()):
	main()


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	flag = 0
	while True:
		s = list(set(a))
		s.sort()
		if len(s) >= k:
			val = s[k - 1]
		else:
			val = s[-1]
		if val == 0 and len(s) > 1:
			flag = 1
			break
		if val == 0 and len(s) == 1:
			break
		for i in range(n):
			if a[i] - val >= 0:
				a[i] -= val
			else:
				a[i] = 0
		ans += 1
	if flag:
		print(-1)
	else:
		print(ans)
	t -= 1


import sys
z = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, z().split())
	a = [*map(int, z().split())]
	s = len(set(a))
	print(1 - 2 * (s > 1) if k < 2 else max(1, -((1 - s) // (k - 1))))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = len(set(a))
	if k == 1 and a.count(a[0]) != n:
		print(-1)
		continue
	if l <= k:
		print(1)
		continue
	else:
		tot = [0] * n
		c = 0
		while 1:
			k1 = k
			if tot[-1] == a[-1]:
				break
			last = 0
			for i in range(n):
				if tot[i] != a[i]:
					if abs(tot[i] - a[i]) == last:
						tot[i] += last
					elif k1 > 0:
						last = abs(tot[i] - a[i])
						tot[i] += last
						k1 -= 1
					else:
						tot[i] += last
				elif i == 0:
					k1 -= 1
			c += 1
		print(c)


import math
x = int(input())
for i in range(x):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = dict()
	for key in a:
		if key in d:
			d[key] += 1
		else:
			d[key] = 1
	z = len(d)
	if k == 1:
		if z == 1:
			print(1)
		else:
			print(-1)
	elif z > k:
		ans = 1
		z -= k
		ans += math.ceil(z / (k - 1))
		print(ans)
	else:
		print(1)


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import sys
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = set(map(int, input().split()))
	n = len(a)
	if n == 1:
		ans = 1
	elif k == 1:
		ans = -1
	else:
		ans = ceil((n - 1) / (k - 1))
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = list(set(l))
	if k == 1 and len(ll) == 1:
		print(1)
	elif k == 1 and len(ll) != 1:
		print(-1)
	else:
		d = len(ll)
		c = 0
		while d > k:
			d = d - k + 1
			c += 1
		if d > 0:
			print(c + 1)
		else:
			print(c)


for _ in range(int(input())):
	[n, k] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	output = 0
	if k == 1:
		if len(set(arr)) > 1:
			print(-1)
		else:
			print(1)
	else:
		j = len(set(arr))
		j -= k
		output += 1
		if j > 0:
			output += j // (k - 1)
			if j % (k - 1) != 0:
				output += 1
		print(output)


import math
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if k == 1:
		if len(set(a)) == 1:
			print(1)
		else:
			print(-1)
	elif len(set(a)) <= k:
		print(1)
	else:
		c = 0
		for i in range(len(a) - 1):
			if a[i] != a[i + 1]:
				c += 1
		print(math.ceil(c / (k - 1)))
	t = t - 1


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) > 1 and k == 1:
		print(-1)
	elif len(set(a)) <= k:
		print(1)
	else:
		print(1 + (len(set(a)) - 2) // (k - 1))


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = len(set(input().split()))
	if k == 1:
		if a > 1:
			print(-1)
		else:
			print(1)
	else:
		print(math.ceil((a - 1) / (k - 1)) or 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	inp = [int(j) for j in input().split()]
	cnt = 0
	flag = 0
	while 1:
		temp = list(set(inp))
		temp.sort()
		if len(temp) >= k:
			minVal = temp[k - 1]
		else:
			minVal = temp[-1]
		if minVal == 0:
			if len(temp) <= 1:
				break
			else:
				flag = 1
				break
		for i in range(n):
			if inp[i] - minVal < 0:
				inp[i] = 0
			else:
				inp[i] = inp[i] - minVal
		cnt += 1
	if flag == 1:
		print(-1)
	else:
		print(cnt)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = set(arr)
	l = len(s)
	if k == 1:
		if l > 1:
			print(-1)
		else:
			print(1)
	elif l <= k:
		print(1)
	elif (l - k) % (k - 1) == 0:
		print(1 + (l - k) // (k - 1))
	else:
		print(2 + (l - k) // (k - 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	temp = len(set(a))
	if k != 1:
		r = temp + k - 3
		print(max(1, r // (k - 1)))
	elif temp == 1:
		print(1)
	else:
		print(-1)


from sys import stdin, stdout
from collections import Counter
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
from math import ceil
mod = 1000000007

def solve():
	(n, k) = mp()
	l = li()
	d = Counter(l)
	val = len(d)
	if k == 1:
		if val != 1:
			pr(-1)
		else:
			pr(1)
		return
	if val <= k:
		pr(1)
	else:
		p = list(d.keys())
		p.sort()
		x = p[:k]
		i = 0
		for j in range(n):
			if l[j] == x[i]:
				l[j] -= x[i]
			else:
				if i + 1 < k:
					i += 1
				l[j] -= x[i]
		ans = 1
		d = Counter(l)
		p = list(d.keys())
		p.sort()
		while p:
			x = p[:k]
			i = 0
			for j in range(n):
				if l[j] == x[i]:
					l[j] -= x[i]
				else:
					if i + 1 < k:
						i += 1
					l[j] -= x[i]
			d = Counter(l)
			p = list(d.keys())
			p.sort()
			ans += 1
			if len(p) == 1 and p == [0]:
				break
		pr(ans)
for _ in range(inp()):
	solve()


for _ in range(int(input())):
	(N, M) = [int(i) for i in input().split(' ')]
	A = [int(i) for i in input().split(' ')]
	count = 1
	for i in range(1, N):
		if A[i] != A[i - 1]:
			count += 1
	if M == 1:
		if count == 1:
			print(1)
		else:
			print(-1)
	elif M >= count:
		print(1)
	else:
		ans = 0
		count -= M
		ans = 1
		if count % (M - 1) == 0:
			ans += count // (M - 1)
			print(ans)
		else:
			ans += count // (M - 1) + 1
			print(ans)


from sys import stdin

def updiv(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
tt = int(stdin.readline())
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	num = 0
	for i in range(n):
		if i == 0:
			num += 1
		elif a[i] != a[i - 1]:
			num += 1
	if k == 1:
		if num == 1:
			print(1)
		else:
			print(-1)
		continue
	elif num <= k:
		print(1)
		continue
	num -= k
	print(updiv(num, k - 1) + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	l = len(s)
	if k == 1 and l > 1:
		print(-1)
	elif l == 1 or l <= k:
		print(1)
	else:
		sol = (l - k + (k - 2)) // (k - 1)
		print(sol + 1)


def is_sorted(li):
	temp = list(li)
	for i in range(0, len(li)):
		if li[i] != temp[i]:
			return False
	return True

def process():
	(n, k) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	if is_sorted(li) == False:
		print('-1')
		return
	elif k == 1 and len(set(li)) == 1:
		print('1')
		return
	elif k > 1:
		ans = 0
		s = len(set(li))
		ans = 1
		s -= k
		while s > 0:
			ans += 1
			s -= k - 1
		print(ans)
	else:
		print('-1')
		return
tests = int(input())
for i in range(tests):
	process()


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
for i in range(test):
	(n, k) = Neo()
	A = Neo()
	A.sort()
	c = 0
	if len(set(A)) == 1:
		print(1)
	elif k == 1:
		if len(set(A)) == 1:
			print(1)
		else:
			print(-1)
	else:
		for (i, j) in zip(A, A[1:]):
			if j - i != 0:
				c += 1
		print(math.ceil(c / (k - 1)))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = len(set(map(int, input().split())))
	if cnt > 1 and k == 1:
		print(-1)
	elif cnt <= k:
		print(1)
	else:
		print(1 + math.ceil((cnt - k) / (k - 1)))


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	discrete = len(set(arr))
	if k == 1:
		print((1, -1)[discrete != 1])
		continue
	else:
		print(max(1, ceil((discrete - 1) / (k - 1))))


from collections import defaultdict
mod = 10 ** 9 + 7
INF = float('inf')

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

def inverse(N, mod):
	return pow(N, mod - 2, mod)

def main():
	T = int(input())
	for _ in range(T):
		(N, K) = getlist()
		A = getlist()
		D = defaultdict(int)
		for i in A:
			D[i] = 1
		M = len(D)
		if K == 1 and M >= 2:
			print(-1)
			continue
		if M == 1:
			print(1)
			continue
		ans = (M - 2) // (K - 1) + 1
		print(ans)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	count = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			count += 1
	if count == 1:
		print(1)
	elif k == 1:
		print(-1)
	elif (count - 1) % (k - 1) == 0:
		print((count - 1) // (k - 1))
	else:
		print((count - 1) // (k - 1) + 1)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lis = [0] * 101
	for i in range(n):
		lis[arr[i]] = 1
	a = lis.count(1)
	if k == 1 and a > 1:
		print(-1)
	else:
		s = 0
		while a > k:
			a -= k - 1
			s += 1
		print(s + 1)


a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	z = list(map(int, input().split()))
	ans = list(set(z))
	if len(ans) > 1 and k == 1:
		print(-1)
		continue
	else:
		t = len(ans)
		cnt = 0
		flag = 0
		while 1:
			if flag == 0:
				t -= k
				flag = 1
				cnt += 1
			else:
				t -= k - 1
				cnt += 1
			if t <= 0:
				break
		print(cnt)


PI = 3.141592653589793
INF = 999999999
MOD = 1000000007
import math

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

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

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	(n, k) = li()
	a = li()
	dist = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			dist += 1
	if k == 1:
		if dist == 1:
			print(1)
		else:
			print(-1)
	else:
		print(max(1, math.ceil((dist - 1) / (k - 1))))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	ans = 0
	for i in a:
		if i not in d:
			d[i] = 1
	l = len(d.keys())
	if k == 1:
		if l == 1:
			print(1)
		else:
			print(-1)
	elif k >= l:
		print(1)
	else:
		l -= k
		ans = 1 + math.ceil(l / (k - 1))
		print(ans)


import collections
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = len(collections.Counter(a))
	if c <= k:
		print(1)
	elif k == 1:
		print(-1)
	else:
		m = (c - 1) // (k - 1)
		if m * (k - 1) + 1 < c:
			m += 1
		print(m)


import sys, math, cmath, time, collections
start_time = time.time()

def solve():
	(n, k) = invr()
	a = inlt()
	q = [a[0]]
	for i in range(len(a)):
		if a[i] != q[-1]:
			q.append(a[i])
	if k == 1:
		if len(q) == 1:
			print(1)
		else:
			print(-1)
	elif len(q) <= k:
		print(1)
	else:
		print(1 + (len(q) - 2) // (k - 1))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def insr():
	return input().strip()

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def ceil(a, b):
	return -(-a // b)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(1)
	elif k == 1:
		if len(set(a)) == 1:
			print(1)
		else:
			print(-1)
	else:
		a1 = [a[i + 1] - a[i] for i in range(n - 1)]
		c = 0
		for i in range(n - 1):
			if a1[i] != 0:
				c += 1
		ans = math.ceil(c / (k - 1))
		print(ans)


from math import ceil
for tc in range(int(input())):
	(n, k) = list(map(int, input().split()))
	s = list(input().split())
	b = 0
	for i in range(len(s) - 1):
		if s[i + 1] != s[i]:
			b += 1
	if b == 0 and k > 0:
		print(1)
	elif k == 1 and b > 0:
		print(-1)
	else:
		print(ceil(b / (k - 1)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set()
	for i in range(n):
		s.add(a[i])
	if k == 1:
		if len(s) > 1:
			print(-1)
		else:
			print(1)
	else:
		sk = len(s) - k
		if sk <= 0:
			print(1)
		elif sk % (k - 1) == 0:
			print(sk // (k - 1) + 1)
		else:
			print(sk // (k - 1) + 2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	num_distinct = len(set(a))
	if num_distinct == 1:
		print(1)
		continue
	elif k == 1:
		print(-1)
		continue
	elif (num_distinct - 1) % (k - 1) == 0:
		print((num_distinct - 1) // (k - 1))
	else:
		print((num_distinct - 1) // (k - 1) + 1)


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

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = [int(x) for x in input().split()]
		x = len(set(a))
		if x > 1 and k == 1:
			print(-1)
		else:
			an = 1
			x -= k
			while x > 0:
				x -= k - 1
				an += 1
			print(an)
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 math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	unique = 0
	prev_element = -1
	for element in map(int, input().split()):
		if element != prev_element:
			unique += 1
			prev_element = element
	if k >= unique:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(1 + math.ceil((unique - k) / (k - 1)))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		z = set()
		flag = 0
		i = 0
		last = -1
		ans = 0
		while i < n:
			ans += 1
			if i == 0:
				z = set()
				q = 0
				for x in range(i, n):
					if l[x] not in z:
						if len(z) + 1 > k:
							q = 1
							break
						else:
							z.add(l[x])
				if q == 1:
					i = x
				else:
					i = x + 1
			else:
				z = set()
				q = 0
				if k - 1 == 0:
					flag = 1
					break
				for x in range(i, n):
					if l[x] not in z:
						if len(z) + 1 >= k:
							q = 1
							break
						else:
							z.add(l[x])
				if q == 1:
					i = x
				else:
					i = x + 1
		if flag == 1:
			print(-1)
		else:
			print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) <= k:
		print(1)
	else:
		m = -1
		n = len(set(a))
		for i in range(1, 101):
			if 1 + ceil((n - 1) / i) <= k:
				m = i
				break
		print(m)


import math
T = int(input())
for t in range(T):
	(N, K) = [int(_) for _ in input().split()]
	A = [int(_) for _ in input().split()]
	nb = len(set(A))
	if K == 1 and nb > 1:
		print(-1)
	else:
		(L, R) = (1, N)
		answer = math.inf
		while L <= R:
			m = (L + R) // 2
			if (m - 1) * (K - 1) + K >= nb:
				R = m - 1
				answer = min(answer, m)
			else:
				L = m + 1
		print(answer)


from math import sqrt, log, ceil, gcd
import sys
from random import randint as r

def solve():
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	st = set(lst)
	dif = len(st)
	if k == 1:
		if dif > 1:
			print(-1)
			return
		print(1)
		return
	if k >= dif:
		print(1)
		return
	print(1 + ceil((dif - k) / (k - 1)))
for _ in range(int(input())):
	solve()


rn = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rns = lambda : map(int, input().split())
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
for _ in range(rn()):
	(n, k) = rns()
	l = rl()
	from math import ceil
	a = len(set(l))
	ans = 0
	if k == 1:
		if a != 1:
			ans = -1
		else:
			ans = 1
	else:
		ans = 1 + max(0, ceil((a - k) / (k - 1)))
	print(ans)


import math
t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	dic = {}
	c = 0
	for i in li:
		if i not in dic:
			dic[i] = 1
			c += 1
	if k == 1 and c > 1:
		print('-1')
	elif k == c:
		print('1')
	elif c < k:
		print('1')
	elif c > k and k != 1:
		c = c - k
		jk = math.ceil(c / (k - 1))
		print(jk + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	distinct = 1
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			distinct += 1
	if k == 1 and distinct > 1:
		print(-1)
	elif distinct <= k:
		print(1)
	else:
		print((distinct - 2) // (k - 1) + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		f = True
		for i in range(1, n):
			if a[i] != a[i - 1]:
				f = False
		if f:
			print(1)
		else:
			print(-1)
		continue
	m = [[0] * n]
	sum_arr = [0] * n
	i = 1
	m[0][0] = a[0]
	cur_b = 0
	last = 0
	while True:
		temp_k = k - 1
		tt = False
		while temp_k != 0:
			if a[i] != a[i - 1]:
				temp_k -= 1
			m[cur_b][i] = a[i] - last
			i += 1
			if i == n:
				tt = True
				break
		if tt:
			break
		l_i = n
		for j in range(i, n):
			m[cur_b][j] = m[cur_b][i - 1]
			if a[j] != a[j - 1] and l_i == n:
				l_i = j
		i = l_i
		if i == n:
			break
		cur_b += 1
		m.append([0] * n)
	print(len(m))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a1 = set(a)
	d = len(a1)
	j = 0
	m = 0
	tot = 0
	while tot < d and k - (j > 0) > 0:
		t = k - (j > 0)
		tot += t
		m += 1
		j += 1
	if tot < d:
		print(-1)
	else:
		print(m)


import math

def array_sum(n, k, l):
	c = 0
	s = set(l)
	ans = 0
	last = None
	if k == 1:
		if len(s) > 1:
			return -1
		else:
			return 1
	for i in range(len(s)):
		c += 1
		if c == k:
			if i == len(s) - 1:
				ans = ans
			else:
				ans += 1
			c = 1
	if ans == 0:
		return 1
	else:
		return 1 + ans
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(array_sum(n, k, l))


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n, k) = gil()
	a = gil()
	if k == 1:
		a.sort()
		if a[0] == a[-1]:
			print(1)
		else:
			print(-1)
	else:
		b = len(set(a))
		cnt = 1
		b -= min(b, k)
		k -= 1
		cnt += b // k + min(b % k, 1)
		print(cnt)


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = set(map(int, input().split()))
	uniq = len(A)
	if k == 1:
		if uniq == 1:
			print(1)
		else:
			print(-1)
	elif k > uniq:
		print(1)
	else:
		print(1 + ceil((uniq - k) / (k - 1)))


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) <= k:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(int((len(set(a)) - k - 0.1) // (k - 1) + 2))


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if len(set(a)) == 1:
			print(1)
			continue
		else:
			print(-1)
			continue
	l = len(set(a))
	if l <= k:
		print(1)
	else:
		print(1 + ceil((l - k) / (k - 1)))


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {}
	for i in a:
		d[i] = True
	if len(d) <= k:
		print(1)
		continue
	elif k == 1 and len(d) > 1:
		print(-1)
		continue
	else:
		l = len(d) - k
		ans = 1
		while l > 0:
			l -= k - 1
			ans += 1
		print(ans)


from math import ceil

def main(n, k, a):
	a = set(a)
	n = len(a)
	if n > k == 1:
		return -1
	if n <= k:
		return 1
	return 1 + ceil((n - k) / (k - 1))
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(main(n, k, a))


import math
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	a = list(map(int, input().split()))
	a = list(set(a))
	n = len(a)
	if k == 1:
		if n <= k:
			print(1)
		else:
			print(-1)
	elif n <= k:
		print(1)
	else:
		p = math.ceil((n - k) / (k - 1))
		print(p + 1)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	cnt = 0
	for i in range(1, n):
		if a[i] - a[i - 1] != 0:
			cnt += 1
	if k == 1 and cnt >= 1:
		print(-1)
		continue
	ans = 1
	cnt -= k
	cnt += 1
	if cnt <= 0:
		print(1)
		continue
	ans += cnt // (k - 1) + int(cnt % (k - 1) != 0)
	print(ans)


import math
for z in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if len(set(a)) > 1 and k == 1:
		print('-1')
	else:
		p = len(set(a))
		cnt = 1
		p -= k
		while p > 0:
			cnt += 1
			p -= k - 1
		print(cnt)


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	(n, k) = M()
	a = L()
	x = len(set(a))
	if k >= x:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(math.ceil((x - 1) / (k - 1)))
for _ in range(I()):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	l = len(set(a))
	if l == 1:
		print(1)
	elif l <= k:
		print(1)
	elif k == 1 and l != 1:
		print(-1)
	else:
		ans = 0
		sumi = -1
		while sumi != 0:
			sumi = 0
			ans += 1
			nc = k
			s = a[0]
			for z in range(n):
				if nc:
					if s != a[z]:
						nc -= 1
						if nc:
							s = a[z]
				a[z] -= s
				sumi += a[z]
		print(ans)


from collections import defaultdict

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
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l = list(set(l))
	l.sort()
	flag = 0
	k1 = 0
	ans = 0
	if len(l) == 1 and k == 1:
		print(1)
		continue
	fl = 0
	for i in range(len(l)):
		if k < 1:
			fl = 1
			break
		if k1 == 0:
			ans += 1
		k1 += 1
		k1 %= k
		if k1 == 0 and flag == 0:
			k -= 1
			flag = 1
	if fl == 1:
		print(-1)
		continue
	print(ans)


from math import ceil as f
for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	z = set(map(int, input().split()))
	p = len(z)
	if p > 1 and k == 1:
		print(-1)
	elif p == 1:
		print(1)
	else:
		print(1 + f((p - k) / (k - 1)))


import math
t = int(input())
for w in range(t):
	(n, k) = (int(i) for i in input().split())
	l = [int(i) for i in input().split()]
	s = set(l)
	s1 = set()
	if len(s) <= k:
		print(1)
	elif k == 1:
		print(-1)
	elif k <= len(s) // 2:
		print(math.ceil((len(s) - (2 * k - 1)) / (k - 1)) + 2)
	else:
		print(2)


def solve():
	case = int(input())
	for _case in range(case):
		(n, k) = map(int, input().split())
		li = list(map(int, input().split()))
		number = 1
		for i in range(1, n):
			if li[i] != li[i - 1]:
				number += 1
		if number == 1:
			print(1)
		elif k == 1:
			print(-1)
		else:
			print((number - 2) // (k - 1) + 1)
solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = 0
	ans = 0
	check = False
	if k == 1 and a.count(a[0]) != n:
		print('-1')
		continue
	elif k == 1 and a.count(a[0]) == n:
		print(1)
		continue
	while sum(a) != 0:
		ans += 1
		cr = a[0]
		cnt = 1
		ind = 0
		a[0] = 0
		for i in range(1, n):
			if a[i] != cr and cnt < k:
				cnt += 1
				cr = a[i]
				a[i] = 0
			else:
				a[i] -= cr
	print(ans)


y = lambda : [*map(int, input().split())]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = y()
	b = len(set(a))
	if k < 2:
		print(1 - 2 * (b > 1))
	else:
		print(max(1, -((1 - b) // (k - 1))))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	n1 = len(s)
	if len(s) == 1:
		print(1)
		continue
	if k == 1 and n1 > 1:
		print(-1)
	else:
		for i in range(1000):
			if k * i - (i - 1) >= n1:
				print(i)
				break


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n, k) = _read_ints()
		a = tuple(_read_ints())
		try:
			result = find_min_m(a, k)
		except ValueError:
			result = -1
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split(' '))

def find_min_m(a_seq, k):
	assert k >= 1
	a_seq = tuple(a_seq)
	if a_seq.count(0) == len(a_seq):
		return 0
	steps_n = sum((x1 != x2 for (x1, x2) in zip(a_seq, a_seq[1:])))
	if k == 1:
		if steps_n == 0:
			return 1
		else:
			raise ValueError("can't find min m")
	result = 0
	steps_per_b_seq = k - 1
	if a_seq[0] != 0:
		steps_n += 1
		if steps_n <= k:
			return 1
		steps_n -= k
		result += 1
	result += _ceil_div(steps_n, steps_per_b_seq)
	return result

def _ceil_div(x, y):
	assert y > 0
	result = x // y
	if x % y != 0:
		result += 1
	return result
main()


t = int(input())
ans = []
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	if k == 1:
		if len(set(A)) != 1:
			ans += [-1]
		else:
			ans += [1]
	elif len(set(A)) <= k:
		ans += [1]
	else:
		if (len(set(A)) - k) % (k - 1) == 0:
			add = 0
		else:
			add = 1
		ans += [(len(set(A)) - k) // (k - 1) + 1 + add]
for i in ans:
	print(i)


import sys
import math
mod = 998244353
dynamic_factorial = False

def main(test_case=False):
	n = int(input()) if test_case else 1
	for _ in range(n):
		test()
		print()

def fast_pow(a: int, b: int):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def c2(n):
	return n * (n - 1) // 2

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

def bits(n: int):
	return list(bin(n)).count('1')

def flush():
	sys.stdout.flush()

def parr(arr):
	print(*arr, sep=' ')

def gcd(a, b):
	while b:
		if b % a == 0:
			break
		tmp = a
		a = b % a
		b = tmp
	return a

def ext_gcd(a: int, b: int):
	if b == 0:
		return [a, [1, 0]]
	res = ext_gcd(b, a % b)
	g = res[0]
	if g != 1:
		return False
	x1 = res[1][0]
	y1 = res[1][1]
	x = y1
	y = x1 - y1 * (a // b)
	return [g, [x, y]]

def get_set(a):
	res = {}
	for x in a:
		if x in res:
			res[x] += 1
		else:
			res[x] = 1
	return res
fact = {0: 1}

def factorial(n):
	if dynamic_factorial:
		if n not in fact:
			fact[n] = factorial(n - 1) * n
		return fact[n]
	else:
		res = 1
		while n > 0:
			res = res * n % mod
			n -= 1
		return res

def sum_of(a):
	res = 0
	for x in a:
		res = (res + x) % mod
	return res

def prod_of(a):
	res = 1
	for x in a:
		res = res * x % mod
	return res

def different_elements(arr):
	ans = 0
	n = len(arr)
	i = 0
	while i < n:
		ans += 1
		while i < n - 1 and arr[i] == arr[i + 1]:
			i += 1
		i += 1
	return ans

def test():
	(n, k) = get()
	a = get()
	if k == 1:
		if a.count(a[0]) == n:
			print(1)
		else:
			print(-1)
	else:
		d = different_elements(a)
		l = k - 1
		s = k
		cnt = 1
		while l > -1 and s < d:
			s += l
			cnt += 1
		if l < 0:
			print(-1)
		else:
			print(cnt)
main(test_case=True)


from math import ceil

def main():
	for _ in range(int(input())):
		(n, k) = tuple(map(int, input().split()))
		a = list(map(int, input().split()))
		if k == 1:
			if min(a) == max(a):
				print(1)
			else:
				print(-1)
		else:
			c = 0
			for i in range(n - 1):
				if a[i] != a[i + 1]:
					c += 1
			if c == 0:
				c += 1
			print(ceil(c / (k - 1)))
main()


from math import ceil

def arrayssum(arr, k):
	if len(set(arr)) == 1:
		return 1
	if k == 1 and len(set(arr)) != 1:
		return -1
	if k == 1:
		return 1
	blanck = []
	for i in range(0, len(arr) - 1):
		blanck.append(arr[i + 1] - arr[i])
	c = len(blanck) - blanck.count(0)
	return ceil(c / (k - 1))
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	print(arrayssum(lst, b))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	arr = l()
	n = len(set(arr))
	if k == 1:
		if n == 1:
			out(1)
			continue
		out(-1)
		continue
	if k >= n:
		out(1)
		continue
	n -= k
	out(1 + n // (k - 1) + (0, 1)[n % (k - 1) != 0])


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = len(set(a))
	if k == 1:
		print(1 - 2 * (l > 1))
	else:
		print(max(1, ceil((l - 1) / (k - 1))))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		acnt = len(set(A))
		if K == 1 and acnt != 1:
			print(-1)
			continue
		acnt -= K
		if acnt <= 0:
			print(1)
			continue
		ans = 1
		ans += -(-acnt // (K - 1))
		print(ans)
main()


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math, itertools

def solve():
	(N, K) = getInts()
	A = getInts()
	set_A = set(A)
	if len(set_A) <= K:
		return 1
	if K == 1:
		return -1
	ans = 0
	for j in range(1, N):
		if A[j] > A[j - 1]:
			ans += 1
	return ans // (K - 1) + (ans % (K - 1) > 0)
for _ in range(getInt()):
	print(solve())


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(n, k) = ip()
	x = ip()
	dis = len(set(x))
	if dis <= k:
		print(1)
		continue
	if 0 in x and dis > 1 and (k == 1):
		print(-1)
		continue
	if k == 1:
		if dis == 1:
			print(1)
		else:
			print(-1)
		continue
	ans = 1
	dis -= k
	ans += (dis - 1) // (k - 1) + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	length = len(set(input().split(' ')))
	if k == 1 and length > 1:
		print(-1)
	elif k >= length:
		print(1)
	else:
		length -= k
		k -= 1
		print((length + k - 1) // k + 1)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	(n, k) = stdarr()
	arr = list(stdarr())
	res = arr.copy()
	ans = 0
	f = True
	while 1:
		s = sorted(list(set(res)))
		if len(s) <= k:
			ans += 1
			break
		cur = s[k - 1]
		if cur == 0 and len(s) != 1:
			f = False
			break
		for i in range(n):
			res[i] = max(res[i] - cur, 0)
		ans += 1
		if len(set(res)) == 1 and res[0] == 0:
			break
	if not f:
		print(-1)
		continue
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1 and len(set(a)) > 1:
		print(-1)
	elif k == 1:
		print(1)
	else:
		c = 0
		while True:
			if c == 1:
				k -= 1
			for j in range(k):
				m = min(a)
				for e in range(n):
					if a[e] != 101:
						a[e] -= m
					if a[e] == 0:
						a[e] = 101
			c += 1
			for e in range(n):
				if a[e] != 101:
					break
			else:
				break
		print(c)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K, A):
	numInc = 0
	for (x, y) in zip(A, A[1:]):
		if x < y:
			numInc += 1
	if numInc == 0:
		return 1
	if K == 1:
		return -1
	M = numInc // (K - 1)
	if numInc % (K - 1) != 0:
		M += 1
	return M
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, K, A)
	print(ans)


from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = set()
	for d in arr:
		s.add(d)
	p = len(s)
	if p <= k:
		print(1)
	elif p - k > 0 and k == 1:
		print(-1)
	elif (p - k) % (k - 1) == 0:
		print((p - k) // (k - 1) + 1)
	else:
		print((p - k) // (k - 1) + 2)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	setlen = len(list(set(s)))
	if k == 1:
		if setlen > 1:
			print(-1)
			continue
	if k >= setlen:
		print(1)
		continue
	setlen -= 1
	k -= 1
	print(math.ceil(setlen / k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = list(set(a))
	a.sort()
	count = 1
	if k == 1 and len(a) > 1:
		print(-1)
	else:
		while sum(a) != 0:
			if len(a) < k:
				count += 1
				break
			max_ele = a[k - 1]
			for i in range(len(a)):
				if a[i] >= max_ele:
					a[i] -= max_ele
				elif a[i] < max_ele:
					a[i] = 0
			a = list(set(a))
			a.sort()
			count += 1
		print(count - 1)


import os, 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))
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
from functools import lru_cache

def main():
	(n, k) = iia()
	arr = iia()
	c = 1
	for i in range(1, n):
		c += arr[i] != arr[i - 1]
	if k == 1:
		if c == 1:
			print(1)
		else:
			print(-1)
	else:
		print(max(1, ceil((c - 1) / (k - 1))))
for _ in range(ii1()):
	main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		if len(set(arr)) > 1:
			print(-1)
		else:
			print(1)
	else:
		print(max(1, (len(set(arr)) - 1 + k - 2) // (k - 1)))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if n == 1:
			print(1)
		elif all((a[i] == a[0] for i in range(n))):
			print(1)
		else:
			print(-1)
		continue
	res = 1
	s = set([])
	pos = 0
	while pos < n:
		s.add(a[pos])
		if len(s) > k:
			break
		else:
			pos += 1
	while pos < n:
		res += 1
		base = a[pos - 1]
		s = set([0])
		while pos < n:
			s.add(a[pos] - base)
			if len(s) > k:
				break
			else:
				pos += 1
	print(res)


from copy import deepcopy
t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if a[0] != a[-1]:
			print(-1)
		else:
			print(1)
		continue
	mat = []
	e = max(a)
	for i in range(e):
		temp = [0] * n
		mat.append(temp)
	for i in range(n):
		elem = a[i]
		for j in range(elem):
			mat[e - 1 - j][i] = 1
	rows = 0
	curr = mat[e - 1]
	j = e - 2
	while j >= 0:
		temp = deepcopy(curr)
		for k1 in range(n):
			temp[k1] += mat[j][k1]
		dist = set(temp)
		if len(dist) > k:
			rows += 1
			curr = mat[j]
			j -= 1
		else:
			j -= 1
			curr = temp
	rows += 1
	print(rows)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	if k == 1 and len(set(A)) != 1:
		print(-1)
		continue
	m = 0
	while True:
		m += 1
		used = 1 if m > 1 else 0
		last = 0 if m > 1 else -1
		for i in range(n):
			if used == k or A[i] == last:
				A[i] -= last
			else:
				last = A[i]
				used += 1
				A[i] -= last
		if all((v == 0 for v in A)):
			break
	print(m)


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print(1)
		return
	diff = 1
	ans = 1
	for (i, v) in enumerate(a):
		if i > 0:
			if v == a[i - 1]:
				continue
			else:
				diff += 1
				if diff > k:
					ans += 1
					diff = 2
	if diff > k:
		print(-1)
	else:
		print(ans)
	return

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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	if len(l) > 1 and k == 1:
		print(-1)
		continue
	if k >= len(l):
		print(1)
		continue
	print(-((1 - len(l)) // (k - 1)))


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	st = list(set(a))
	size = len(st)
	if size == k:
		print(1)
		continue
	if k == 1:
		print(-1)
	else:
		size -= k
		if size < 0:
			print(1)
		else:
			print(1 + ceil(size / (k - 1)))


from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	ln = len(set(a))
	if k == 1:
		if ln == 1:
			print(1)
		else:
			print(-1)
	else:
		c = 0
		ln -= 1
		print(max(1, ceil(ln / (k - 1))))


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	(n, k) = MI()
	aa = LI()
	cnt = 0
	for i in range(n - 1):
		if aa[i] != aa[i + 1]:
			cnt += 1
	if cnt == 0:
		print(1)
		continue
	if k == 1:
		print(-1)
		continue
	ans = (cnt + k - 2) // (k - 1)
	print(ans)


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, k) = mints()
	p = -5
	q = -1
	for i in mints():
		if i != p:
			q += 1
		p = i
	if k == 1:
		if q > 0:
			print(-1)
		else:
			print(1)
		return
	print(max((q + k - 2) // (k - 1), 1))
for i in range(mint()):
	solve()


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters[:26]
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	first = list(map(int, input().split()))
	bf = len(set(first))
	if k == 1:
		if bf > 1:
			print(-1)
		else:
			print(1)
		continue
	res = 0
	if bf >= k:
		res += 1
		bf -= k
	print(res + bf // (k - 1) + (1 if bf % (k - 1) else 0))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = len(set(a))
	if k == 1:
		if l > k:
			print(-1)
		else:
			print(1)
	else:
		coun = 0
		while l > 0:
			if coun == 0:
				l -= k
			else:
				l -= k - 1
			coun += 1
		print(coun)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			p += 1
	if p <= k:
		print(1)
	elif k != 1:
		print((p + k - 3) // (k - 1))
	else:
		print(-1)


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

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt, pow
for _ in range(N()):
	(n, k) = RL()
	a = RLL()
	l = len(set(a))
	if k == 1 and l > 1:
		print(-1)
	elif l == 1:
		print(1)
	else:
		res = 1
		l -= k
		if l > 0:
			res += ceil(l / (k - 1))
		print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	elems = len(set([*map(int, input().split())]))
	if k == 1 and elems > 1:
		print(-1)
	elif k >= elems:
		print(1)
	else:
		print(max(1, (elems - 1 + k - 2) // (k - 1)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1 and len(set(a)) > 1:
		print(-1)
	else:
		s = set()
		prev = None
		result = 1
		for x in a:
			if x != prev:
				s.add(x)
				prev = x
				if len(s) > k:
					result += 1
					s = {0, x}
		print(result)


from math import *
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(n, k) = M()
	a = LI()
	d = Counter(a)
	b = len(d)
	if k == 1 and b > 1:
		print(-1)
	elif b == 1 or b <= k:
		print(1)
	else:
		ans = (b - k + (k - 2)) // (k - 1)
		print(ans + 1)


from collections import defaultdict, Counter
from math import log, ceil, floor
from itertools import accumulate

def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	c = set(a)
	x = len(c)
	x = x - k
	ans = 1
	if x != 0 and k == 1:
		print(-1)
	else:
		while x > 0:
			x = x - (k - 1)
			ans += 1
		print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	e = b
	count = 1
	if len(set(c)) == b:
		print(1)
	elif b - 1 == 0:
		print(-1)
	else:
		while e < len(set(c)):
			e = e + (b - 1)
			count = count + 1
		print(count)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	l = len(set(list(map(int, input().strip().split()))))
	if k == 1:
		if l > 1:
			print('-1')
		else:
			print('1')
	else:
		total = 1
		l -= k if l > k else l
		total += math.ceil(l / (k - 1))
		print(total)


(lambda W: [(lambda N, K, n: print(1 if all((n[i] == n[i + 1] for i in range(N - 1))) else -1) if K == 1 else (lambda b, k: (lambda ns, bs, ks: print(len(list(W(lambda i: n[-1] and (bs(0, -1), ks(0, 0), [ns(i, n[i] - b[0]) if k[0] == K else (n[i] != b[0] and (bs(0, n[i]), ks(0, k[0] + 1)), ns(i, 0)) for i in range(N)]), (i for i in range(999)))))))(n.__setitem__, b.__setitem__, k.__setitem__))([0], [0]))(*map(int, input().split()), list(map(int, input().split()))) for t in range(int(input()))])(__import__('itertools').takewhile)


from collections import defaultdict
for i1 in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dict = defaultdict(int)
	for i in l:
		dict[i] += 1
	p = len(dict)
	if k >= p:
		print(1)
		continue
	if k == 1:
		print(-1)
		continue
	else:
		ans = 1
		check = (p - k) / (k - 1)
		if check == int(check):
			ans += int(check)
		else:
			ans += int(check) + 1
		print(ans)


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(int(input())):
	(n, k) = put()
	l = list(put())
	if len(set(l)) <= k:
		print(1)
	elif len(set(l)) > 1 and k == 1:
		print(-1)
	elif (len(set(l)) - k) % (k - 1) == 0:
		print(1 + (len(set(l)) - k) // (k - 1))
	else:
		print(2 + (len(set(l)) - k) // (k - 1))


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def pw(a, b, md):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
			result %= md
		a *= a
		a %= md
		b //= 2
	return result % md

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = inpt()
		ar = inpt()
		ar = list(set(ar))
		ar.sort()
		if len(ar) > 1 and k == 1:
			print(-1)
			continue
		prev = -1
		if k >= len(ar):
			print(1)
			continue
		rem = len(ar) - k
		ans = 1
		ad = math.ceil(rem / (k - 1))
		ans += ad
		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')
threading.Thread(target=main).start()


import os
from sys import stdin, stdout

class Input:

	def __init__(self):
		self.lines = stdin.readlines()
		self.idx = 0

	def line(self):
		try:
			return self.lines[self.idx].strip()
		finally:
			self.idx += 1

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

	def known_tests(self):
		(num_of_cases,) = self.array()
		for case in range(num_of_cases):
			yield self

	def unknown_tests(self):
		while self.idx < len(self.lines):
			yield self

def problem_solver():

	def solver(inpt):
		(n, k) = inpt.array()
		a = inpt.array()
		df = 1
		for i in range(1, n):
			if a[i - 1] != a[i]:
				df += 1
		if k == 1 and df > 1:
			print(-1)
		else:
			count = 0
			while df > 0:
				count += 1
				df -= k
				if df > 0:
					df += 1
			print(count)
	return solver
try:
	solver = problem_solver()
	for tc in Input().known_tests():
		solver(tc)
except Exception as e:
	import traceback
	traceback.print_exc(file=stdout)


import math
teststring = '6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n'
online = __file__ != '/home/jhli/py/Grakn/Problem_B.py'
(true, false) = (True, False)
if True:

	def spitout():
		for c in teststring.splitlines():
			yield c
	_ito = spitout()
	if not online:

		def input():
			return next(_ito)

	def build_enum(*a):
		built = dict()
		for (i, c) in enumerate(a):
			built[c] = i
		return lambda x: built[x]
T = int(input())
for ti in range(1, T + 1):
	[n, k] = map(int, input().split(' '))
	a = []
	a.extend([int(e) for e in input().split(' ')])
	d = 0
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			d += 1
	if k == 1:
		if d == 0:
			print(str(1))
		else:
			print(str(-1))
	elif d == 0:
		print(str(1))
	else:
		print(str(math.ceil(d / (k - 1))))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	k1 = 0
	B = [0 for i in range(101)]
	for i in A:
		if B[i] == 0:
			k1 = k1 + 1
			B[i] = 1
	if k >= k1:
		print(1)
	elif k == 1:
		print(-1)
	else:
		ans = 1
		val = k1 - k
		ans = ans + val // (k - 1)
		if val % (k - 1) != 0:
			ans = ans + 1
		print(ans)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a = set(a)
	count = len(a)
	ans = 0
	if k == 1 and count > 1:
		print(-1)
	else:
		ans = 1
		count -= k
		k -= 1
		while count > 0:
			count -= k
			ans += 1
		print(ans)
	t -= 1


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		a = list(set(a))
		if len(a) <= k:
			print(1)
			continue
		if k == 1:
			print('-1')
			continue
		x = len(a) - k
		k -= 1
		z = x // k
		if x % k:
			z += 1
		print(z + 1)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, OrderedDict, deque
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(I()):
	(n, k) = tup()
	ls = lint()
	N = len(set(ls))
	if N > 1 and k < 2:
		print(-1)
	elif N == k:
		print(1)
	else:
		print(max(1, -((1 - N) // (k - 1))))
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


(T,) = map(int, input().split())
for _ in range(T):
	(N, K) = map(int, input().split())
	X = list(map(int, input().split()))
	if K == 1:
		if len(set(X)) == 1:
			print(1)
		else:
			print(-1)
		continue
	b = 0
	vs = set()
	c = 0
	R = 1
	for x in X:
		if x - b not in vs:
			c += 1
			if not c > K:
				vs.add(x - b)
		if c > K:
			c = 1
			R += 1
			b = x
			vs = set()
			if x - b not in vs:
				c += 1
				vs.add(x - b)
	print(R)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nList = list(map(int, input().rstrip().split()))
	ans = 0
	l = len(set(nList))
	if k == 1:
		if l != 1:
			print(-1)
		if l == 1:
			print(1)
	else:
		ans = 1
		l = l - k
		if l <= 0:
			print(ans)
			continue
		while True:
			l = l - (k - 1)
			ans += 1
			if l <= 0:
				print(ans)
				break


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	C = [0 for i in range(101)]
	for i in L:
		C[i] = C[i] + 1
	a = d = 0
	for i in C:
		if i != 0:
			a = a + 1
	if a > 1 and k == 1:
		print(-1)
	else:
		if C[0] > 0:
			k = k - 1
			a = a - 1
		if k == 0 and a == 0:
			print(1)
		else:
			a = max(0, a - k)
			d = d + 1
			if C[0] == 0:
				k = max(1, k - 1)
			d = d + ceil(a / k)
			print(d)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = set(a)
	e = len(r) - k
	if k == 1 and len(r) != 1:
		print(-1)
	elif k == 1 and len(r) == 1:
		print(1)
	elif e <= 0:
		print(1)
	elif e % (k - 1) == 0:
		print(e // (k - 1) + 1)
	else:
		print(e // (k - 1) + 2)


import re
from string import ascii_lowercase
from math import inf, ceil, factorial, log
from collections import defaultdict, deque, Counter
from bisect import bisect, insort, bisect_left, bisect_right
mod = int(1000000000.0) + 7

def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 0
	while any((ele for ele in arr)):
		original = list(arr)
		taken = set()
		for i in range(n):
			if len(taken) < k or arr[i] in taken:
				taken.add(arr[i])
				arr[i] = 0
		if arr == original:
			ans = -1
			break
		ans += 1
	print(max(ans, 1) if ans != -1 else -1)

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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	s = set(lst)
	l = len(s)
	if k == 1 and l > 1:
		print(-1)
	elif k == 1 and l == 1:
		print(1)
	elif k < l:
		if (l - 1) % (k - 1) == 0:
			print((l - 1) // (k - 1))
		else:
			print((l - 1) // (k - 1) + 1)
	elif k >= l:
		print(1)


import math
test = int(input())
for q in range(test):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = set()
	if k == 1:
		if a[0] != a[n - 1]:
			print(-1)
			continue
		else:
			print(1)
			continue
	ans = 0
	i = 0
	while i < n:
		x.add(a[i])
		if len(x) == k + 1:
			x = set()
			x.add(a[i])
			ans = 1
			break
		i += 1
	if i == n:
		print(1)
		continue
	for j in range(i, n):
		x.add(a[j])
	ans += math.ceil(len(x) / (k - 1))
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	a = 0
	for i in range(1, n):
		if s[i] > s[i - 1]:
			a += 1
	if a == 0:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print((a + k - 2) // (k - 1))


from typing import List

def solve(k: int, a: List[int]) -> int:
	a_set = set()
	for val in a:
		a_set.add(val)
	if len(a_set) > 1 and k == 1:
		return -1
	if len(a_set) == 1:
		return 1
	m = 1
	tmp = len(a_set)
	tmp -= k
	if tmp > 0:
		m += (tmp - 1) // (k - 1) + 1
	return m
test_cases = int(input())
for _ in range(test_cases):
	inputs = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	print(solve(inputs[1], a))


import os
import sys
from io import BytesIO, IOBase
DEBUG_MODE = False

def main():
	T = iin()
	while T:
		T -= 1
		(n, k) = lin()
		a = lin()
		ans = -1
		st = list(set(a))
		st.sort()
		for m in range(1, 110):
			if len(set(st)) <= k:
				ans = m
				break
			last = st[k - 1]
			st = [0] + [val - last for val in st[k:]]
		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')

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
if DEBUG_MODE == True:
	import cProfile
	cProfile.run('main()')
else:
	main()


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	(n, k) = map(int, stdin.readline().strip().split())
	a = list(map(int, stdin.readline().strip().split()))
	x = len(set(a)) - k
	if x <= 0:
		print(1)
		continue
	if k == 1:
		print(-1)
		continue
	ans = 1 + x // (k - 1)
	if x % (k - 1) != 0:
		ans += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = 0
	for i in range(n - 1):
		if l[i] < l[i + 1]:
			d += 1
	if d == 0:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(int((d + k - 2) / (k - 1)))


from collections import defaultdict
import math
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	diff = 0
	d = defaultdict(int)
	for i in arr:
		d[i] += 1
	diff = len(d)
	if diff <= k:
		print(1)
	elif k == 1:
		print(-1)
	elif k == 2:
		print(diff - 1)
	else:
		print(max(0, math.ceil((diff - k) / (k - 1))) + 1)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if len(set(a)) == 1:
			print(1)
		else:
			print(-1)
		continue
	count = 0
	c = 1
	flag = True
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			count += 1
	print(max((count + k - 2) // (k - 1), 1))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	if k == 1 and len(s) > 1:
		print(-1)
	elif len(s) == k:
		print(1)
	else:
		ans = 1
		p = len(s) - k
		ans1 = math.ceil(p / (k - 1))
		if ans1 > 0:
			ans += ans1
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	ans = 1
	for i in l:
		d[i] = d.get(i, 0) + 1
	if k == 1:
		if len(d) != 1:
			print(-1)
		else:
			print(ans)
	elif len(d) <= k:
		print(ans)
	else:
		p = sorted(list(d.keys()))
		v = p[:k]
		j = 0
		for i in range(n):
			if l[i] - v[j] == 0:
				l[i] = 0
			else:
				if j + 1 < k:
					j += 1
				l[i] -= v[j]
		d = {}
		for i in l:
			d[i] = d.get(i, 0) + 1
		p = sorted(list(d.keys()))
		while len(p) > 0:
			v = p[:k]
			ans += 1
			j = 0
			for i in range(n):
				if l[i] - v[j] == 0:
					l[i] = 0
				else:
					if j + 1 < k:
						j += 1
					l[i] -= v[j]
			d = {}
			for i in l:
				d[i] = d.get(i, 0) + 1
			p = sorted(list(d.keys()))
			if p == [0]:
				break
		print(ans)


t = int(input())
for i in range(t):
	(n, k) = input().strip().split(' ')
	(n, k) = [int(n), int(k)]
	a = list(map(int, input().strip().split(' ')))
	p = list(set(a))
	if k == 1 and len(p) > 1:
		print(-1)
	elif k == 1 and len(p) == 1:
		print(1)
	else:
		ff = len(p)
		ff -= k
		ans = 1
		if ff <= 0:
			print(ans)
		else:
			if ff % (k - 1):
				ans += ff // (k - 1) + 1
			else:
				ans += ff // (k - 1)
			print(ans)


def solution(n, k, a):
	res = 1
	if k == 1:
		for i in range(1, n):
			if a[i] != a[0]:
				return -1
		return 1
	cnt = 1
	cur = a[0]
	for index in range(1, n):
		if cur == a[index]:
			continue
		if cnt == k:
			res += 1
			cnt = 1
		cnt += 1
		cur = a[index]
	return res
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solution(n, k, a))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	m = len(set(lst)) - 1
	if k == 1:
		print(-1 if m else 1)
	else:
		print(1 + max(0, (m - 1) // (k - 1)))


def ceil_div(y, k):
	return (y + (k - 1)) // k
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = set(a)
	d = len(b)
	zero = False
	for x in b:
		if x == 0:
			zero = True
	if k == 1:
		if d > 1:
			print(-1)
		else:
			print(1)
		continue
	if zero:
		print(ceil_div(d - 1, k - 1))
	elif d <= k:
		print(1)
	else:
		d -= k
		print(1 + ceil_div(d, k - 1))


import sys
import math
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	s = set()
	total = 0
	for j in range(n):
		s.add(arr[j])
	if k == 1 and len(s) > 1:
		print(-1)
	elif k == 1 and len(s) == 1:
		print(1)
	else:
		while True:
			d = k
			last = -1
			for j in range(n):
				if arr[j] == last:
					arr[j] = 0
				elif d > 0:
					d -= 1
					last = arr[j]
					arr[j] = 0
				else:
					arr[j] -= last
			total += 1
			if arr[n - 1] == 0:
				break
		print(total)


ans = []
for t in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	h = {}
	for v in a:
		h[v] = True
	u = len(h)
	if k == 1:
		ans.append(1 if u == 1 else -1)
	else:
		ans.append(max(1, (u - 1 + k - 2) // (k - 1)))
for a in ans:
	print(a)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	N = len(set(a))
	if N <= k:
		print(1)
	elif N > 1 and k < 2:
		print(-1)
	else:
		print(math.ceil((N - k) / (k - 1)) + 1)


import sys
import bisect

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

def removeDuplicate(arr):
	ans = [arr[0]]
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			ans.append(arr[i])
	return ans
t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr = removeDuplicate(arr)
	start_values = []
	ans = 0
	diff_val_used = 0
	last_val_used = -1
	existing_sum = 0
	for j in range(0, len(arr)):
		val_to_cover = arr[j] - existing_sum
		if last_val_used == -1:
			ans += 1
			if j == 0:
				last_val_used = val_to_cover
				diff_val_used = 1
			else:
				last_val_used = val_to_cover
				diff_val_used = 2
				if k == 2:
					existing_sum = arr[j]
					diff_val_used = 0
					last_val_used = -1
		elif last_val_used != val_to_cover:
			if diff_val_used > k - 1:
				print(-1)
				break
			elif diff_val_used == k - 1:
				existing_sum = arr[j]
				diff_val_used = 0
				last_val_used = -1
			elif diff_val_used < k - 1:
				diff_val_used += 1
				last_val_used = val_to_cover
	else:
		print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		array = list(map(int, input().split()))
		diff = 0
		for i in range(1, n):
			if array[i] > array[i - 1]:
				diff += 1
		if k == 1:
			if diff > 0:
				yield (-1)
			else:
				yield 1
		elif diff == 0:
			yield 1
		elif diff % (k - 1):
			yield (diff // (k - 1) + 1)
		else:
			yield (diff // (k - 1))
t = int(input())
ans = gift()
print(*ans, sep='\n')


import math
t = int(input())
for j in range(0, t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = 0
	if k == 1:
		for i in range(0, n - 1):
			if a[i] != a[i + 1]:
				d = -1
				print(-1)
				break
		if d != -1:
			print(1)
	else:
		rt = set(a)
		yz = len(rt)
		if yz <= k:
			print(1)
		else:
			uu = 1
			yz = yz - k
			if yz % (k - 1) == 0:
				uu += yz // (k - 1)
			else:
				uu += yz // (k - 1) + 1
			print(uu)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(x) for x in input().split()]
	if k == 1:
		flag = 0
		for i in A:
			if A[0] != i:
				flag = 1
		if flag == 1:
			print(-1)
		else:
			print(1)
	else:
		x = set(A)
		if len(x) <= k:
			print(1)
		else:
			print(max(1, (len(x) - 1 + (k - 2)) // (k - 1)))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	dist = len(set(l))
	if dist <= k:
		print(1)
		continue
	if k == 1:
		print(-1)
	else:
		ans = (dist - k) // (k - 1) + 1
		if (dist - k) % (k - 1):
			ans += 1
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = set(map(int, input().split()))
	if len(l) == 1:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print((len(l) - 2 + (k - 1)) // (k - 1))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	diff = len(set(l))
	if k >= diff:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(math.ceil((diff - 1) / (k - 1)))


from sys import stdin, exit, setrecursionlimit
setrecursionlimit(100000000)
from math import *
from bisect import bisect_left
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	(n, k) = mi()
	a = lmi()
	if k == 1:
		if len(set(a)) > 1:
			print(-1)
		else:
			print(1)
		continue
	if k >= len(set(a)):
		print(1)
	else:
		print(ceil((len(set(a)) - k) / (k - 1)) + 1)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda : list(map(int, input().split()))

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

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(n, k) = aj()
	A = aj()
	diff = len(set(A))
	if k >= diff:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(math.ceil((diff - 1) / (k - 1)))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = array()
	dist = len(set(a))
	if k == 1:
		if dist == 1:
			print(1)
		else:
			print(-1)
	else:
		ans = 0
		cur = sorted(set(a))
		while True:
			ans += 1
			d = 1
			ok = False
			cur[0] = 0
			for i in range(1, len(cur)):
				if cur[i] != cur[i - 1]:
					d += 1
					if d == k:
						key = cur[i]
				if d <= k:
					cur[i] = 0
				else:
					ok = True
					cur[i] = key
			if not ok:
				break
		print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	l = I()
	st = len(set(l))
	m = 1
	if k == 1 and st != 1:
		m = -1
	elif k >= st:
		m = 1
	else:
		m = 1 + (st - 2) // (k - 1)
	print(m)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == len(set(arr)):
		print(1)
	else:
		ans = 0
		f = 0
		for _ in range(1000):
			if len(set(arr)) == 1:
				f = 1
				break
			c = 0
			have = defaultdict(int)
			for i in range(n):
				if arr[i] in have:
					arr[i] = 0
					continue
				elif c < k:
					c += 1
					have[arr[i]] = 1
					arr[i] = 0
			ans += 1
		if f:
			print(max(1, ans))
		else:
			print(-1)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
import io
import os
import operator
input = sys.stdin.readline
import random
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(n, k) = cin()
	l = ain()
	d = dd(int)
	for i in l:
		d[i] += 1
	ke = list(d.keys())
	lek = len(ke)
	if k == 1:
		if len(ke) > 1:
			print(-1)
		else:
			print(1)
	elif lek <= k:
		print(1)
	else:
		print((lek - 2) // (k - 1) + 1)


for i in range(int(input())):
	(n, k) = [int(num) for num in input().split()]
	x = list(map(int, input().split()))
	if len(set(x)) <= k:
		print(1)
	elif k < 2:
		print(-1)
	else:
		c = len(set(x))
		c1 = c - k
		c1 = c1 // (k - 1)
		if (c - k) % (k - 1) == 0:
			print(c1 + 1)
		else:
			print(c1 + 2)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	temp = [arr[i] for i in range(n)]
	last = [0 for i in range(n)]
	cnt = 0
	while arr != last:
		mex = arr[0]
		uni = 1
		arr[0] = 0
		for i in range(1, n):
			if arr[i] == mex:
				arr[i] = 0
			elif uni < k:
				mex = arr[i]
				uni += 1
				arr[i] = 0
			else:
				arr[i] -= mex
		cnt += 1
		if arr == temp:
			cnt = -1
			break
		else:
			temp = [arr[i] for i in range(n)]
	print(cnt)


def readis():
	return map(int, input().strip().split())

def printlist(xs):
	print(' '.join(map(str, xs)))
T = int(input())
while T:
	T -= 1
	(n, k) = readis()
	A = list(readis())
	n_uniq = len(set(A))
	if k == 1:
		if n_uniq == 1:
			print(1)
		else:
			print(-1)
	else:
		print(1 + max(n_uniq - k + k - 2, 0) // (k - 1))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	sb = len(set(A))
	if k == 1:
		if sb == 1:
			print(1)
		else:
			print(-1)
		continue
	print(1 + max(0, math.ceil((sb - k) / (k - 1))))


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if len(set(a)) == 1:
			print(1)
		else:
			print(-1)
		continue
	m = 0
	while a[-1]:
		d = 1
		ld = a[0]
		a[0] = 0
		for i in range(1, n):
			if ld == a[i]:
				a[i] -= ld
			elif d < k:
				ld = a[i]
				a[i] = 0
				d += 1
			else:
				a[i] -= ld
		m += 1
	print(m)


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	unique = len(set(arr))
	if k == 1:
		if unique == 1:
			print(1)
		else:
			print(-1)
	elif k >= unique:
		print(1)
	else:
		rem = unique - k
		ans = 1
		ans += int(math.ceil(rem / (k - 1)))
		print(ans)


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		c = list(map(int, input().split()))
		p = [0] * n
		p[0] = a[0]
		for i in range(1, n - 1):
			if a[i] != p[i - 1]:
				p[i] = a[i]
			else:
				p[i] = b[i]
		if a[n - 1] != p[0] and a[n - 1] != p[n - 2]:
			p[n - 1] = a[n - 1]
		elif b[n - 1] != p[0] and b[n - 1] != p[n - 2]:
			p[n - 1] = b[n - 1]
		else:
			p[n - 1] = c[n - 1]
		print(*p)

def B():
	from math import ceil
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a = len(sorted(list(set(a))))
		if a <= k:
			print(1)
		else:
			a -= k
			if k == 1:
				print(-1)
			else:
				print(1 + ceil(a / (k - 1)))

def C():
	t = int(input())
	for _ in range(t):
		__ = 0

def D():
	t = int(input())
	for _ in range(t):
		__ = 0

def E():
	t = int(input())
	for _ in range(t):
		__ = 0

def F():
	t = int(input())
	for _ in range(t):
		__ = 0
B()


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = len(set(a))
	if k == 1:
		if x == 1:
			print(1)
		else:
			print(-1)
	elif x == 1:
		print(1)
	else:
		print(ceil((x - 1) / (k - 1)))


import os
import sys
import io
import functools
import copy
import math
GANS = []

def cmp(x, y):
	if x[1] == y[1]:
		return y[0] - x[0]
	return x[1] - y[1]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	li = [int(i) for i in input().split()]
	base = li[0]
	if k == 1:
		done = True
		for i in li[1:]:
			if i != base:
				print(-1)
				done = False
				break
		if done:
			print(1)
		continue
	ans = 1
	cur = 1
	dif = 1
	for (p, i) in enumerate(li[1:]):
		p += 1
		if i != base:
			cur += 1
			dif += 1
			base = i
			if cur > k:
				cur %= k
				ans += 1
	print(max(1, int(1 + math.ceil(max(0, dif - k) / (k - 1)))))


gans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	u = []
	for i in range(1, n):
		if a[i] == a[i - 1]:
			continue
		u.append(a[i - 1])
	u.append(a[-1])
	if len(u) > 1 and k == 1:
		ans = -1
	elif k == 1:
		ans = 1
	elif len(u) == 1:
		ans = 1
	else:
		ans = max(len(u) - 1 - 1, 0) // (k - 1) + 1
	gans.append(ans)
print('\n'.join(map(str, gans)))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = []
	while True:
		b_i = []
		ind = 0
		for num in range(k):
			b_i.append(a[ind])
			for (ind_a, el) in enumerate(a):
				if ind != ind_a:
					if a[ind] == a[ind_a]:
						b_i.append(a[ind_a])
					elif a[ind] > a[ind_a]:
						continue
					else:
						ind = ind_a
						break
		b_i.extend([b_i[-1]] * (n - ind))
		ind_a = 0
		nexus = a.copy()
		while ind_a < n:
			a[ind_a] = 0 if b_i[-1] > a[ind_a] else a[ind_a] - b_i[-1]
			ind_a += 1
		flag = 0
		if nexus == a:
			flag = 1
			break
		b.append(b_i.copy())
		if a[-1] == 0:
			break
	print(len(b) if flag == 0 else -1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 1
	for i in range(n - 1):
		if a[i + 1] > a[i]:
			ans += 1
	if ans <= k:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print((ans - k - 1) // (k - 1) + 2)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(a) for a in input().split()]
	ls1 = []
	ctr = 0
	for i in range(1, n, 1):
		ls1.append(ls[i] - ls[i - 1])
		if ls1[-1] != 0:
			ctr += 1
	if k == 1:
		if len(set(ls)) == 1:
			print(1)
		else:
			print(-1)
	elif len(set(ls)) == 1:
		print(1)
	else:
		print(math.ceil(ctr / (k - 1)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		if len(set(arr)) != 1:
			print(-1)
		else:
			print(1)
		continue
	else:
		ans = 1
		pos = 0
		cnt = 0
		prev = -1
		while pos < n:
			if prev < arr[pos]:
				cnt += 1
				if cnt > k:
					ans += 1
					cnt = 1
					continue
				prev = arr[pos]
			pos += 1
		print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	st = set(a)
	if k == 1 and len(st) > 1:
		print(-1)
		continue
	res = 0
	b = [0] * n
	b[0] = a[0]
	while True:
		kek1 = 0
		kek = 0
		for i in range(1, n):
			if a[i] != a[i - 1]:
				kek1 += 1
			if kek1 < k:
				kek = a[i]
			b[i] = kek
		for i in range(0, n):
			a[i] -= b[i]
		res += 1
		b[0] = 0
		if a.count(0) == len(a):
			break
	print(res)


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		if len(set(arr)) == 1:
			print(1)
		else:
			print(-1)
			continue
	else:
		if len(set(arr)) == 1:
			print(1)
			continue
		a = []
		for i in range(n - 1):
			a.append(arr[i + 1] - arr[i])
		c = a.count(0)
		c = len(a) - c
		print(ceil(c / (k - 1)))


import math
t = int(input())
for _ in range(0, t):
	ss = set()
	ls1 = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	elements = len(set(ls))
	k = ls1[1]
	if k == 1:
		if elements > 1:
			print(-1)
		else:
			print(1)
	else:
		ans = 1
		elements -= k
		k -= 1
		while elements > 0:
			elements -= k
			ans += 1
		print(ans)


import sys
input = sys.stdin.readline

def main():
	(n, k) = map(int, input().split())
	alst = list(map(int, input().split()))
	if k == 1:
		if alst[0] == alst[-1]:
			print(1)
		else:
			print(-1)
		return
	cnt = 0
	bef = alst[0]
	for a in alst[1:]:
		if bef != a:
			cnt += 1
		bef = a
	k -= 1
	ans = (cnt + k - 1) // k
	print(max(ans, 1))
for _ in range(int(input())):
	main()


from collections import Counter
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	z = Counter()
	c = 0
	an = 0
	p = True
	for j in range(n):
		if z[a[j]] == 0:
			c += 1
		z[a[j]] += 1
		if c == k:
			c = 0
			if p:
				k -= 1
				p = False
			an += 1
	if c > 0:
		an += 1
	print(an if k != 0 else -1 if len(set(a)) != 1 else 1)


import math
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = len(set(a))
	ans = 0
	if b <= k:
		ans = 1
	elif k == 1 and b != 1:
		ans = -1
	else:
		b -= k
		ans = math.ceil(b / (k - 1))
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	aS = set(a)
	u = len(aS)
	answer = 0
	if 0 not in aS:
		u -= min(k - 1, u - 1)
		answer += 1
	k -= 1
	if k == 0:
		if u == 1:
			print(answer)
		else:
			print(-1)
	else:
		allSame = (u + k - 2) // k
		print(answer + allSame)


from math import *
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	diff = 1
	c = a[0]
	for i in a:
		if i == c:
			pass
		else:
			diff += 1
			c = i
	ans = 1
	diff -= k
	k -= 1
	if k == 0 and diff != 0:
		print(-1)
	else:
		if k != 0:
			ans += ceil(diff / k)
		print(max(1, ans))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = set(map(int, input().split()))
	if k == 1:
		if len(a) != 1:
			print(-1)
		else:
			print(1)
	else:
		print(1 + max(0, math.ceil((len(a) - k) / (k - 1))))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			cnt += 1
	if k == 1:
		if [a[0]] * n == a:
			print(1)
		else:
			print(-1)
	else:
		print(max(1, (cnt + k - 2) // (k - 1)))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans += 1
	if k == 1:
		if ans > 1:
			print(-1)
		else:
			print(1)
	else:
		print(int(math.ceil(max(ans - k, 0) / (k - 1))) + int(ans > 0))


t = int(input())
for l in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) > k and k == 1:
		print(-1)
	elif k >= len(set(a)):
		print(1)
	else:
		print(max(1, (len(set(a)) + k - 3) // (k - 1)))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = len(set(a))
	if k == 1 and cnt > 1:
		print(-1)
		continue
	cnt = max(0, cnt - k)
	if cnt == 0:
		print(1)
		continue
	ans = 1
	k -= 1
	ans += (cnt + k - 1) // k
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	C = len(list(set([int(a) for a in input().split()])))
	if C <= K:
		print(1)
	elif K == 1:
		print(-1)
	else:
		print((C - 1 + K - 2) // (K - 1))


import sys
import math

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q), 2):
		n = q[i][0]
		k = q[i][1]
		a = q[i + 1]
		u = len(set(a))
		if k == 1 and u != 1:
			print(-1)
		elif k == 1 or u == 1:
			print(1)
		else:
			ret = math.ceil((u - k) / (k - 1))
			print(ret + 1)
main()


import os
import math
true = True
false = False
from functools import reduce
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins():
	return list(map(int, input_().split(' ')))

def inss():
	return list(input_().split(' '))

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def ranin():
	return range(int(input_()))

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
for _ in range(int(input_())):
	(n, k) = ins()
	a = ins()
	unique_a_count = len(set(a))
	if k == 1:
		print_(-1 if unique_a_count > 1 else 1)
	elif unique_a_count - k <= 0:
		print_(1)
	else:
		unique_a_count -= k
		print_(math.ceil(unique_a_count / (k - 1)) + 1)
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


import sys
import math
MOD = 1000000007

def solve():
	pass
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = len(set(a))
	if k >= c:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print(math.ceil((c - 1) / (k - 1)))


for query in range(int(input())):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	a = [int(x) - 1 for x in input().split()]
	x = [False] * 101
	count = 0
	for y in range(n):
		x[a[y]] = True
	for y in range(101):
		if x[y]:
			count += 1
	if count != 1 and k == 1:
		print(-1)
		continue
	if count == 1:
		print(1)
		continue
	if (count - 1) % (k - 1) == 0:
		print((count - 1) // (k - 1))
	else:
		print((count - 1) // (k - 1) + 1)


import math
T = int(input())
for _ in range(T):
	(n, k) = tuple(map(int, input().split()))
	x = list(map(int, input().split()))
	s = set()
	for i in range(len(x)):
		s.add(x[i])
	if k == 1:
		if len(s) > 1:
			print(-1)
		else:
			print(1)
	elif k > len(s):
		print(1)
	else:
		print(math.ceil((len(s) - k) / (k - 1)) + 1)


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(n, k) = [int(x) for x in R().split()]
			a = [int(x) for x in R().split()]
			a = list(set(a))
			if k == 1 and len(a) > 1:
				ans.append('-1')
				continue
			elif len(a) <= k:
				ans.append('1')
				continue
			cnt = 1
			while len(a) > k:
				taken = a[k - 1]
				for j in range(k):
					a[j] = 0
				for j in range(k, len(a)):
					a[j] -= taken
				cnt += 1
				a = list(set(a))
			ans.append(str(cnt))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


testCase = int(input())

def func(arr, k):
	(t, cnt) = (-1, 0)
	for i in range(len(arr)):
		if arr[i] != t:
			cnt += 1
		t = arr[i]
		if cnt == k + 1:
			return [0] * i + [j - arr[i - 1] for j in arr[i:]]
	return [0] * len(arr)
for tc in range(testCase):
	(m, flag) = (0, 0)
	(n, k) = map(int, input().split())
	num = list(map(int, input().split()))
	while num.count(0) != len(num):
		t = num.copy()
		num = func(num, k)
		if t == num:
			flag = 1
			break
		m += 1
	print(-1 if flag else m)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	index = 0
	count = 0
	ss = 0
	prev = -1
	res = 0
	find = True
	while index < n:
		temp = arr[index] - ss
		if prev == temp:
			index += 1
			continue
		else:
			prev = temp
			count += 1
			if count > k:
				find = False
				break
			if count == k:
				ss += prev
				res += 1
				prev = 0
				count = 1
			index += 1
	if find is False:
		print(-1)
	else:
		if count > 1 or res == 0:
			res += 1
		print(res)
	T -= 1


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

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

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

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

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	(n, k) = MAP()
	arr = LIST()
	arr1 = list(set(arr))
	if len(arr1) != 1 and k == 1:
		print(-1)
	elif k == 1 and len(arr1) == 1:
		print(1)
	else:
		length = len(arr1)
		ans = 0
		if length == 1:
			print(1)
		else:
			while length > 1:
				length -= k - 1
				ans += 1
			print(ans)


import bisect
import array
import functools
import math
mo = 1000000007
T = int(input())
for Tid in range(T):
	(n, k) = map(int, input().split())
	a = array.array('i', map(int, input().split()))

	def solve1():
		if a[0] == a[n - 1]:
			print(1)
		else:
			print(-1)

	def solve2():
		sum = 0
		for i in range(1, n):
			if a[i] != a[i - 1]:
				sum = sum + 1
		print(max(1, (sum + k - 2) // (k - 1)))
	if k == 1:
		solve1()
	else:
		solve2()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	v = list(map(int, input().split()))
	fv = [0] * 101
	for x in v:
		fv[x] += 1
	dist = 0
	for i in range(0, 101):
		if fv[i] > 0:
			dist += 1
	k = min(k, dist)
	if k == 1:
		print(-1 if dist > 1 else 1)
	else:
		print(1 + (dist - 2) // (k - 1))


import math

def main():
	t = int(input())
	for t_ in range(t):
		(n, k) = list(map(int, input().split(' ')))
		a = list(map(int, input().split(' ')))
		s = set(a)
		if k == 1:
			if len(s) == 1:
				print(1)
			else:
				print(-1)
		elif len(s) == 1:
			print(1)
		else:
			print(int(math.ceil((len(s) - 1) / (k - 1))))
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
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
mod = 10 ** 9 + 7

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 zerolist(n):
	return [0] * n

def nextline():
	out('\n')

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

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

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

def solve(case):
	(n, k) = sep()
	a = lis()
	ans = 0
	diff = len(set(a))
	if k == 1:
		if diff > 1:
			print(-1)
		else:
			print(1)
		return
	ans += 1
	diff -= k
	ans += 0 if diff < 0 else ceil(diff / (k - 1))
	print(ans)
testcase(int(inp()))


import sys
from collections import deque
from copy import *
from bisect import *

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()

def cil(a, b):
	return a // b + int(a % b > 0)
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	b = list(set(a))
	if k == 1:
		print(-1 if len(b) > 1 else 1)
		continue
	if k >= len(b):
		print(1)
		continue
	n = len(b)
	ans = z = 0
	while z != n:
		i = z
		ans += 1
		prevz = z
		c = 0 if i == 0 else 1
		while c < k and i < n:
			b[i] = 0
			c += 1
			z += 1
			i += 1
		if z == prevz:
			break
	print(ans if z == n else -1)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import defaultdict
from pprint import pprint
from math import ceil

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ind = 0
	m = 0
	t = 0
	while t < 110:
		m += 1
		cnt = k
		sub = -1
		for i in range(ind, n):
			if arr[i] != sub and cnt > 0:
				assert arr[i] >= sub
				cnt -= 1
				sub = arr[i]
				arr[i] -= sub
			else:
				arr[i] -= sub
		if sum(arr) == 0:
			break
		t += 1
	if sum(arr) == 0:
		print(m)
	else:
		print(-1)
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')
for _ in range(int(input())):
	main()


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	a = [0] * 101
	distinct = 0
	for i in arr:
		if a[i] == 0:
			distinct += 1
		a[i] += 1
	if k >= distinct:
		print(1)
	elif k == 1:
		print(-1)
	else:
		x = ceil((distinct - k) / (k - 1))
		print(x + 1)


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = mi()
	a = list(set(list(mi())))
	uniq = len(a)
	if k == 1:
		if uniq > 1:
			print(-1)
		else:
			print(1)
		continue
	if uniq <= k:
		print(1)
		continue
	uniq -= k
	print(1 + (uniq + k - 2) // (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = list(set(arr))
	arr.sort()
	n = len(arr)
	if k >= 1 and n == 1:
		print(1)
		continue
	if k == 1 and n > 1:
		print(-1)
		continue
	c = len(arr) - 1
	ans = c / (k - 1)
	if int(ans) == ans:
		ans = int(ans)
	else:
		ans = int(ans) + 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	l = len(set(a))
	if k >= l:
		print(1)
		continue
	else:
		temp = l - k
		try:
			ans = math.ceil(temp / (k - 1)) + 1
		except:
			ans = -1
		print(ans)


import math
t = int(input())
for case in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	if k == 1:
		if len(set(a)) == 1:
			ans = 1
		else:
			ans = -1
	else:
		ans = max(1, math.ceil((len(set(a)) - 1) / (k - 1)))
	print(ans)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k1 = k
	ls = list(map(int, input().split()))
	cnt = 0
	d = dict()
	ans = 1
	if k == 1 and len(set(ls)) > 1:
		print(-1)
		continue
	for i in range(n):
		if d.get(ls[i]) is None:
			cnt += 1
			d[ls[i]] = 1
			if k == 0:
				ans += 1
				k = k1 - 2
			else:
				k -= 1
		else:
			d[ls[i]] += 1
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	count = 0
	fl = True
	maxLastWas = arr[-1]
	while True:
		count += 1
		f = arr[0]
		t = 1
		lastWas = arr[0]
		arr[0] = 0
		for i in range(1, n):
			if arr[i] == lastWas:
				arr[i] -= f
			elif t < k:
				t += 1
				f = arr[i]
				lastWas = arr[i]
				arr[i] = 0
			else:
				arr[i] -= f
		if maxLastWas == arr[-1]:
			fl = False
			break
		else:
			if arr[-1] == 0:
				break
			maxLastWas = arr[-1]
	if fl:
		print(count)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			d += 1
	if k == 1 and d > 1:
		print(-1)
	elif k == 1 and d == 1 or d <= k:
		print(1)
	else:
		print(1 + (d - k) // (k - 1) + 1 * ((d - k) % (k - 1) != 0))


import os, io
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()))
	shiftcount = 0
	for i in range(1, n):
		if a[i] > a[i - 1]:
			shiftcount += 1
	if k == 1:
		if shiftcount == 0:
			print(1)
		else:
			print(-1)
	else:
		t = shiftcount // (k - 1)
		if shiftcount % (k - 1) != 0:
			t += 1
		print(max(1, t))


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	if k == 1:
		if len(c) > 1:
			ans = -1
		else:
			ans = 1
	else:
		ans = 1 + max(0, int(math.ceil((len(c) - k) / (k - 1))))
	print(ans)


import sys
import itertools as it
import bisect as bi
import math as mt
import collections as cc
input = sys.stdin.readline
S = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	l = I()
	nn = len(set(l))
	if nn > 1 and k - 1 == 0:
		print(-1)
	elif k >= nn:
		print(1)
	else:
		print(1 + (nn - 2) // (k - 1))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	dist = len(set(a))
	if k == 1 and dist > 1:
		print(-1)
		continue
	op = 0
	while a[-1] != 0:
		new = [a[0]]
		dist = 1
		op += 1
		for v in a[1:]:
			if dist + 1 > k:
				break
			new += [v]
			if new and new[-1] != new[-2]:
				dist += 1
		while len(new) != n:
			new += [new[-1]]
		for i in range(n):
			a[i] -= new[i]
	print(op)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = inar()
		arr = inar()
		counter = 0
		temp = 0
		i = 0
		ans = 1
		arr = list(set(arr))
		n = len(arr)
		if n <= k:
			print(1)
		else:
			if k == 1:
				print(-1)
				continue
			while i < n:
				temp += 1
				if temp > k:
					temp = 1
					ans += 1
					continue
				i += 1
			print(ans)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set()

	def arrsum():
		s.clear()
		m = 1
		for i in range(n):
			s.add(a[i])
			if len(s) == k:
				break
		sm = 0
		for i in range(n):
			if a[i] - sm not in s:
				if len(s) < k:
					s.add(a[i] - sm)
				else:
					m += 1
					mx = max(s)
					sm += mx
					s.clear()
					s.add(0)
					s.add(a[i] - sm)
		if len(s) > k:
			return -1
		return m
	print(arrsum())


from math import ceil

def check(a):
	b = [bool(a[i] == a[i + 1]) for i in range(n - 1)]
	return False not in b
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		if check(a):
			print(1)
		else:
			print(-1)
	elif check(a):
		print(1)
	else:
		x = []
		for i in range(1, n):
			x.append(a[i] - a[i - 1])
		c = 0
		for i in x:
			if i != 0:
				c += 1
		print(ceil(c / (k - 1)))


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	if k == 1:
		poss = 1
		for i in li:
			if i != li[0]:
				poss = 0
				break
		if poss:
			print(1)
		else:
			print(-1)
		continue
	count = 0
	for i in range(n - 1):
		if li[i] != li[i + 1]:
			count += 1
	count += 1
	for i in range(1, 400):
		if (i - 1) * (k - 1) + k >= count:
			ans = i
			break
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	x = len(set(a))
	if k == 1:
		if x > 1:
			ans = -1
		else:
			ans = 1
	elif x <= k:
		ans = 1
	else:
		x -= k
		ans = 1
		ans += x // (k - 1)
		if x % (k - 1) != 0:
			ans += 1
	print(ans)


from sys import *
from math import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	if k == 1:
		x = [a[0]] * n
		if x != a:
			print(-1)
		else:
			print(1)
	else:
		b = [a[0]]
		for i in range(1, n):
			if a[i] != a[i - 1]:
				b.append(a[i])
		x = len(b)
		x -= k
		ans = 1
		while x > 0:
			x -= k - 1
			ans += 1
		print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	p = list(set(a))
	if k == 1:
		if len(p) == 1:
			print(1)
		else:
			print(-1)
	elif len(p) <= k:
		print(1)
	else:
		ans = 1 + (len(p) - 2) // (k - 1)
		print(ans)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if k == 1:
		if min(arr) != max(arr):
			print(-1)
		else:
			print(1)
	else:
		s = len(set(arr))
		if s <= k:
			print(1)
		else:
			ans = 1
			s -= k
			k -= 1
			ans += math.ceil(s / k)
			print(ans)


import sys, os.path
from collections import *
from heapq import *
from copy import *
import math
mod = 10 ** 9 + 7
read = lambda : map(int, input().split())
inf = float('inf')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	(n, k) = read()
	a = list(read())
	c = Counter(a)
	if len(c) == 1 and k == 1:
		print(1)
	elif len(c) != 1 and k == 1:
		print(-1)
	else:
		l = len(c)
		if k >= l:
			print(1)
		else:
			print((l - 2) // (k - 1) + 1)


mod = 10 ** 9 + 7

def solve():
	ans = -1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for x in a:
		d[x] = 1
	if k == 1:
		if len(d) != 1:
			ans = -1
		else:
			ans = 1
	else:
		l = len(d)
		ans = max((l + k - 3) // (k - 1), 1)
	print(ans)
t = int(input())
while t > 0:
	solve()
	t -= 1


import sys
from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
from statistics import mean, median, mode
alpha = ascii_lowercase
beta = ascii_uppercase

def nextPowerOf2(n):
	p = 1
	if n and (not n & n - 1):
		return n
	while p < n:
		p <<= 1
	return p

def get_Divisors(n):
	arr = []
	i = 1
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				arr.append(i)
			else:
				arr.append(i)
				arr.append(n // i)
		i = i + 1
	return arr

def isprime(n):
	if n == 1:
		return 0
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1

def Sieve(n):
	prime = [True for i in range(n + 1)]
	prime[0] = False
	prime[1] = False
	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 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 main():
	for ttt in range(int(input())):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		if k == 1:
			if len(set(arr)) == 1:
				print(1)
			else:
				print(-1)
		else:
			if len(set(arr)) == 1:
				print(1)
				continue
			kk = len(set(arr))
			print(ceil((kk - 1) / (k - 1)))
main()


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

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

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		aa = set(a)
		al = len(aa)
		if k == 1:
			if al > 1:
				print(-1)
			else:
				print(1)
		else:
			ans = 1
			al -= k
			while al > 0:
				al -= k - 1
				ans += 1
			print(ans)
main()


from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	c = Counter(A)
	U = len(c.keys())
	if U == 1:
		print(1)
	elif k > 1:
		U -= 1
		(q, r) = divmod(U, k - 1)
		if r == 0:
			print(q)
		else:
			print(q + 1)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	data = set(map(int, input().split()))
	if len(data) > 1 and k == 1:
		print(-1)
	elif len(data) <= k:
		print(1)
	elif (len(data) - k) % (k - 1) == 0:
		print(1 + (len(data) - k) // (k - 1))
	else:
		print(1 + (len(data) - k) // (k - 1) + 1)


from math import *
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	n = len(s)
	if n == k:
		print(1)
		continue
	if k == 1 and n > 1:
		print(-1)
		continue
	elif k == 1 and n == 1:
		print(1)
		continue
	cnt = 0
	s = list(s)
	for i in range(n):
		j = 0
		flag = 1
		lst = s[i]
		cnt += 1
		for l in range(i, n):
			if s[l] == 0 and flag:
				j += 1
				flag = 0
				continue
			elif s[l] == 0:
				continue
			if j < k:
				lst = s[l]
				s[l] -= s[l]
				j += 1
			else:
				s[l] -= lst
		if s[n - 1] == 0:
			break
	print(cnt)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

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

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * (2 * 10 ** 5 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(2 * 10 ** 5 + 5):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj
mod = 10 ** 9 * 2

def solve():
	(n, k) = IP()
	a = L()
	ff = len(set(a))
	if ff <= k:
		print(1)
		return
	if k == 1:
		eq = 0
		mk = [a[0]] * n
		if mk == a:
			print(1)
			return
		else:
			print(-1)
			return
	else:
		st = len(list(set(a)))
		m = 1
		while True:
			st -= k
			if st <= 0:
				break
			else:
				m += 1
				st += 1
		print(m)
		return
t = II()
for i in range(t):
	solve()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.append(-9)
	count = 0
	for i in range(n):
		if a[i] != a[i + 1]:
			count += 1
	(plus, score) = (0, 0)
	if k == 1 and count > 1:
		print(-1)
		continue
	while True:
		score = k + (k - 1) * plus
		if score >= count:
			break
		plus += 1
	print(plus + 1)


def solve():
	t = inp()
	for _ in range(t):
		(n, k) = mul()
		l = len(set(seq()))
		if k == 1:
			if l > 1:
				print('-1')
			else:
				print('1')
		else:
			total = 1
			l -= k if l > k else l
			total += ceil(l / (k - 1))
			print(total)
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = a[0]
	c = 1
	d = [a[0]]
	for i in a:
		if i == b:
			b = i
		else:
			c += 1
			d += [i]
			b = i
	if c <= k:
		print(1)
		continue
	hjo = 0
	for m in range(2, n + 1):
		if 2 + (c - 2) // m <= k:
			print(m)
			hjo = 1
			break
	if hjo != 1:
		print(-1)


import sys
import os
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')
from decimal import Decimal as d
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def min1(lst):
	(minn, ind) = (float('inf'), 0)
	for i in range(len(lst)):
		if lst[i] < minn:
			minn = lst[i]
			ind = i
	return (minn, ind)

def solve(n, k, lst):
	lst1 = [1]
	for i in range(1, n):
		if lst[i] > lst[i - 1]:
			(minn, ind) = min1(lst1)
			if minn >= k:
				lst1.append(1)
				lst1[-1] += 1
			else:
				lst1[ind] += 1
	maxx = max(lst1)
	if maxx <= k:
		return len(lst1)
	return -1
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	print(solve(n, k, lst))


t = int(input())
for nbt in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	nbc = len(set(a)) - 1
	if k == 1:
		if nbc:
			print(-1)
		else:
			print(1)
	else:
		print(1 + max(0, (nbc - 1) // (k - 1)))


cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	v1 = sorted(list(set(a)))
	vl = len(v1)
	if k == 1 and vl != 1:
		print(-1)
	else:
		m = 1
		while vl > k:
			a = [i if i > v1[k - 1] else 0 for i in a]
			v1 = sorted(list(set(a)))
			vl = len(v1)
			m += 1
		print(m)


def solve(n, k, arr):
	num = len(set(arr))
	if k == 1:
		if num == 1:
			return 1
		return -1
	if num <= k:
		return 1
	return (num + k - 3) // (k - 1)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(n, k, arr))


import sys, math
import io, os
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	(n, k) = mdata()
	a = mdata()
	if k == 1:
		if len(set(a)) != 1:
			out(-1)
		else:
			out(1)
		continue
	cnt = 1
	ans = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			cnt += 1
		if cnt == k:
			ans += 1
			cnt = 1
	if cnt > 1 or ans == 0:
		ans += 1
	out(ans)


import sys
from collections import deque, defaultdict, namedtuple
import heapq
from math import sqrt, factorial, gcd, ceil, atan, pi

def input():
	return sys.stdin.readline()[:-1]
import string
import operator
import random
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')

def solve():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	ans = 0
	last = a[:]
	ok = 1
	while ok:
		ans += 1
		ok = 0
		cur = [a[0]]
		for (i, e) in enumerate(a):
			if e > cur[-1] and len(cur) < k:
				cur.append(e)
			a[i] -= cur[-1]
		if a != last:
			if len(set(a)) == 1:
				print(ans)
				return
			ok = 1
			last = a[:]
	print(-1)
T = 1
T = int(input())
for case in range(1, T + 1):
	ans = solve()


import sys

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

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

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

def list4d(a, b, c, d, e):
	return [[[[e for l in range(d)] for k 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 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')
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** (-10)
for _ in range(INT()):
	(N, K) = MAP()
	A = LIST()
	ans = INF
	for i in range(1, N + 1):
		B = [1] * i
		k = 1
		for j in range(1, N):
			if A[j] - A[j - 1] != 0:
				B[k % i] += 1
				k += 1
		mx = 0
		for k in range(i):
			mx = max(mx, B[k])
		if mx <= K:
			ans = min(ans, i)
			break
	if ans == INF:
		print(-1)
	else:
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = len(set(list(map(int, input().split()))))
	if k != 1:
		print(max(0, (A - 2) // (k - 1)) + 1)
	elif A != 1:
		print(-1)
	else:
		print(1)


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	rem = a[:]
	if len(set(a)) <= k:
		print(1)
	elif k == 1:
		print(-1)
	else:
		print((len(set(a)) - 1 + k - 2) // (k - 1))


def ceil(a, b):
	return (a + b - 1) // b

def solve():
	(N, K) = map(int, input().split())
	A = set([int(x) for x in input().split()])
	if K == 1:
		return 1 if len(A) == 1 else -1
	if len(A) <= K:
		return 1
	return ceil(len(A) - K, K - 1) + 1
TC = int(input())
for _ in range(TC):
	print(solve())


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = len(set(l))
	if k == 1:
		if s > 1:
			print(-1)
		else:
			print(1)
	elif s <= k:
		print(1)
	else:
		print((s - 2) // (k - 1) + 1)


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
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	if k == 1:
		if len(s) > 1:
			print(-1)
		else:
			print(1)
	else:
		p = len(s)
		r = 1 + max(math.ceil((p - k) / (k - 1)), 0)
		print(r)


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1 and len(set(a)) != 1:
		print(-1)
	else:
		difo = len(set(a))
		if k >= difo:
			print(1)
		else:
			print(ceil((difo - k) / (k - 1)) + 1)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations, combinations_with_replacement, product
from collections import *
import timeit, time
M = 10 ** 9 + 7
import heapq
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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 fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

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 binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r, p)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def calcSum(arr, n, k):
	l = []
	sum = 0
	for i in range(k):
		sum += arr[i]
	l.append(sum)
	for i in range(k, n):
		sum = sum - arr[i - k] + arr[i]
		l.append(sum)
	return l

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

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

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def main():
	for _ in range(inpu()):
		(n, k) = sep()
		arr = lis()
		b = len(set(arr))
		if k < 2:
			print(1 - 2 * (b > 1))
		else:
			print(max(1, -((1 - b) // (k - 1))))
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	c = len(set(A))
	if k - 1 == 0:
		if c - 1 > 0:
			print(-1)
		else:
			print(1)
	else:
		ans = (c - 1 + (k - 1) - 1) // (k - 1)
		print(max(1, ans))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	st = len(set(l))
	if k == 1 and st != 1:
		print(-1)
	elif k >= st:
		print(1)
	else:
		print(1 + (st - 2) // (k - 1))


TC = int(input())
for tc in range(TC):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	result = 0
	tmp = A.copy()
	noZeros = True
	while noZeros:
		noZeros = False
		count = 0
		last = -1
		for i in range(N):
			if count >= K:
				if last == 0:
					result = -2
					noZeros = False
					break
				tmp[i] -= last
				if tmp[i] > 0:
					noZeros = True
			elif tmp[i] > last:
				last = tmp[i]
				count += 1
				tmp[i] = 0
			else:
				tmp[i] = 0
		result += 1
	print(result)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [A[0]]
	for a in A:
		if a == B[-1]:
			continue
		else:
			B.append(a)
	LEN = len(B)
	if k == 1:
		if LEN == 1:
			print(1)
		else:
			print(-1)
		continue
	if LEN <= k:
		print(1)
		continue
	LEN -= k
	print(1 + (LEN + (k - 2)) // (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = set([int(x) for x in input().split()])
	if k == 1:
		print(-1 if len(a) > 1 else 1)
	else:
		print(max(1, (len(a) + k - 2 - 1) // (k - 1)))


import math
t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	l = len(set(b))
	if k == 1 and l > 1:
		print(-1)
	elif k == 1:
		print(1)
	else:
		print(max(0, math.ceil((l - k) / (k - 1))) + 1)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = len(set(l))
	if k >= c:
		print(1)
		continue
	elif k == 1:
		print(-1)
	else:
		print(ceil((c - 1) / (k - 1)))


import sys, math
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	(n, k) = inpl()
	a = inpl()
	ln = len(set(a))
	if k == 1 and ln > 1:
		print(-1)
		continue
	if ln == 1:
		print(1)
		continue
	ln -= 1
	k -= 1
	print((ln + k - 1) // k)


testCases = int(input())
for j in range(0, testCases):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	if k == 1:
		allEqual = True
		for i in range(0, n):
			if a[i] != a[0]:
				allEqual = False
		if allEqual:
			print(1)
		else:
			print(-1)
		continue
	different = 1
	arrayCount = 1
	numsNeeded = k
	for i in range(1, n):
		if a[i] != a[i - 1]:
			different += 1
			if different > numsNeeded:
				arrayCount += 1
				different = 1
				numsNeeded = k - 1
	print(arrayCount)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set(a)
	if len(s) > 1 and k == 1:
		print(-1)
		continue
	if len(s) <= k:
		print(1)
		continue
	ans = 1 + (len(s) - k) // (k - 1)
	if (len(s) - k) % (k - 1):
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	ans = 0
	arr = [int(num) for num in input().split(' ')]
	if k == 1 and len(set(arr)) != 1:
		ans = -1
	elif arr[0] == 0 and len(set(arr)) == 1:
		ans = 1
	else:
		while arr[0] != 0 or len(set(arr)) != 1:
			i = 0
			a = set()
			a.add(arr[0])
			while i < n and len(set(a)) <= k:
				a.add(arr[i])
				if len(a) > k:
					break
				else:
					arr[i] = 0
					i = i + 1
			for j in range(i, n):
				arr[j] = arr[j] - arr[i - 1]
			ans = ans + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().strip().split(' '))
	lst = list(map(int, input().strip().split(' ')))
	l = len(list(set(lst)))
	if k == 1 and l > 1:
		print(-1)
	else:
		j = 1
		while True:
			p1 = k * j - (j - 1)
			p2 = k * (j + 1) - j
			if l <= p1:
				print(j)
				break
			elif l > p1 and l <= p2:
				print(j + 1)
				break
			else:
				j += 1


from collections import *
from itertools import *
from bisect import *

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

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

def main():
	t = inp()
	for _ in range(t):
		(n, k) = arrinp()
		A = arrinp()
		distinct = set(A)
		curr = len(distinct)
		if k <= 1 and curr > k:
			print(-1)
			continue
		if curr <= k:
			print(1)
			continue
		m = 0
		while len(distinct) >= k:
			m += 1
			temp = list(distinct)
			sub = temp[k - 1]
			distinct = set()
			n = len(temp)
			l = n - 1
			while l >= k - 1:
				distinct.add(temp[l] - sub)
				l -= 1
		if len(distinct) > 1:
			m += 1
		print(m)
main()


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		flg = [int(i) for i in input().split()]
		mp = {i: 0 for i in range(101)}
		for i in flg:
			mp[i] += 1
		c = 0
		for i in range(101):
			if mp[i] != 0:
				c += 1
		if c <= k:
			print(1)
		else:
			c1 = c - k
			if k - 1 == 0:
				print(-1)
			else:
				if c1 % (k - 1) == 0:
					ans = c1 // (k - 1)
				else:
					ans = c1 // (k - 1) + 1
				ans += 1
				print(ans)
except EOFError as e:
	print(e)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	f = defaultdict(int)
	for i in a:
		f[i] += 1
	d = len(f)
	if k == 1 and d != 1:
		print(-1)
		continue
	if k >= d:
		print(1)
		continue
	left = d - k
	print(1 + (left + k - 2) // (k - 1))


from collections import defaultdict
import sys
import math

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	a = get_array()
	if len(set(a)) <= k:
		print(1)
		continue
	if k == 1:
		print(-1)
		continue
	l = len(set(a))
	ans = 1
	l -= k
	while l > 0:
		l -= k - 1
		ans += 1
	print(ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		cnt = 0
		for i in range(n):
			if i == 0 or a[i] != a[i - 1]:
				cnt += 1
		if k == 1 and cnt == 1:
			print(1)
		elif k == 1:
			print(-1)
		else:
			case = 1
			ans = 0
			while case < cnt:
				ans += 1
				case += k - 1
			print(max(ans, 1))
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def calc(sa, k):
	if sa == k:
		return 1
	if k == 1 and sa > 1:
		return -1
	result = 0
	if sa > k:
		sa -= k
		result += 1
	result += sa // (k - 1)
	if sa % (k - 1) != 0:
		result += 1
	return result
T = int(input())
for t in range(T):
	st = input().split()
	k = int(st[1])
	a = input().split()
	a = list(dict.fromkeys(a))
	sa = len(a)
	print(calc(sa, k))


import sys, os, io

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

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		if k == 1:
			if len(set(a)) == 1:
				print(1)
			else:
				print(-1)
		else:
			c = 0
			for i in range(1, n):
				if a[i] - a[i - 1]:
					c += 1
			A = c
			B = k - 1
			print(max(1, (A + B - 1) // B))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return 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(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
for xyz in range(0, int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	le = len(set(l))
	if k == 1:
		if le > 1:
			print(-1)
		else:
			print(1)
	elif k >= le:
		print(1)
	else:
		t = le - k
		print(1 + math.ceil(t / (k - 1)))


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
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()
	if k == 1:
		if a[0] == a[-1]:
			print(1)
		else:
			print(-1)
	else:
		x = len(set(a))
		if x <= k:
			print(1)
			continue
		else:
			tot = 1
			p = -1
			dc = 0
			i = 0
			while i < n:
				if p == a[i]:
					i += 1
					continue
				else:
					dc += 1
					p = a[i]
					i += 1
					if dc > k:
						break
		i -= 1
		x = len(set(a[i:]))
		print(tot + ceil(x / (k - 1)))