Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.

A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. [Image] The figure shows a 4-output splitter 

Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.

Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.


-----Input-----

The first line contains two space-separated integers n and k (1 ≤ n ≤ 10^18, 2 ≤ k ≤ 10^9).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Output-----

Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.


-----Examples-----
Input
4 3

Output
2

Input
5 5

Output
1

Input
8 4

Output
-1

Difficulty: MEDIUM_HARD
Tags: Sorting

Mathematics
Skill types: Sorting
Expected Time Complexity: O(Log(N))

Starter code:

Solutions:
def main():
	(n, k) = map(int, input().split())
	n -= 1
	k -= 1
	if n == 0:
		minSplitters = 0
	elif n <= k:
		minSplitters = 1
	elif n > sum_consecutive(k):
		minSplitters = -1
	else:
		minSplitters = min_splitters(n, k)
	print(minSplitters)

def min_splitters(n, k):
	(low, high) = (1, k)
	while low < high:
		mid = (low + high) // 2
		summation = sum_consecutive2(mid, k)
		if summation == n:
			return k - mid + 1
		elif summation > n:
			low = mid + 1
		else:
			high = mid
	return k - low + 2

def sum_consecutive(num):
	return int(0.5 * num * (num + 1))

def sum_consecutive2(num1, num2):
	return sum_consecutive(num2) - sum_consecutive(num1 - 1)
main()


import math
(n, k) = map(int, input().split())
n -= 1
k -= 1
if n > k * (k + 1) // 2:
	print(-1)
else:
	l = -1
	r = k + 1
	while r > l + 1:
		m = (l + r) // 2
		if n > m * (2 * k - m + 1) // 2:
			l = m
		else:
			r = m
	print(r)


(a, b) = map(int, input().split())
c = 2 * (a - 1) - b * (b - 1)
if c > 0:
	print(-1)
else:
	d = int((1 + (1 - 4 * c) ** 0.5) / 2)
	if d * (d - 1) + c > 0:
		d -= 1
	print(b - d)


(n, k) = map(int, input().split())
m = 2 * (n - 1) - k * (k - 1)
if m > 0:
	print(-1)
else:
	x = int((1 + (1 - 4 * m) ** 0.5) / 2)
	while x * x - x + m > 0:
		x -= 1
	print(k - x)


(n, k) = map(int, input().split())
(l, r) = (-1, k + 1)
while l + 1 < r:
	mid = l + r >> 1
	val = (k - mid + 1 + k) * mid // 2 - (mid - 1)
	if val < n:
		l = mid
	else:
		r = mid
print(-1 if r == k + 1 else r)


(z, x) = map(int, input().split())
z -= 1
x -= 1
if x * (x + 1) / 2 < z:
	print(-1)
elif z == 0:
	print(0)
elif z == x:
	print(1)
else:
	import sys
	start = 1
	end = x
	while end > start:
		mid = (end + start) // 2
		ans = x * (x + 1) // 2 - (mid - 1) * mid // 2
		if ans == z:
			print(x - mid + 1)
			sys.exit(0)
		elif ans > z:
			start = mid + 1
		elif ans < z:
			end = mid
	print(x - end + 2)


f = lambda m, k: k * m - m * (m - 1) // 2 - m + 1

def ok(m, k, n):
	return f(m, k) >= n
(n, k) = map(int, input().split())
if not ok(k, k, n):
	print(-1)
else:
	(l, h) = (0, k)
	while h > l:
		mid = l + (h - l) // 2
		if ok(mid, k, n):
			h = mid
		else:
			l = mid + 1
	print(h)


(N, K) = map(int, input().split())

def in_bounds(k):
	return N <= K * (K + 1) // 2 - (K - k) * (K - k + 1) // 2 - k + 1
l = 0
r = K
while l <= r:
	c = (l + r) // 2
	if in_bounds(c):
		r = c - 1
	else:
		l = c + 1
if in_bounds(K):
	print(l)
else:
	print(-1)


(n, k) = map(int, input().split())
(n, k) = (n - 1, k - 1)
l = 0
r = k
g = k * (k + 1) // 2
ans = -1
while l <= r:
	m = (l + r) // 2
	if g - m * (m + 1) // 2 >= n:
		ans = k - m
		l = m + 1
	else:
		r = m - 1
print(ans)


import sys
(n, k) = map(int, input().split())
k -= 1
(lo, hi) = (0, int(1000000000.0))
while lo < hi:
	m = (lo + hi + 1) // 2
	if 1 + k * (k + 1) // 2 - m * (m + 1) // 2 >= n:
		lo = m
	else:
		hi = m - 1
if 1 + k * (k + 1) // 2 - lo * (lo + 1) // 2 >= n:
	lo = k - lo
else:
	lo = -1
print(lo)


def sum(n):
	return n * (n + 1) // 2

def range_sum(left, right):
	return sum(right) - sum(left - 1)

def binary_search(k, n):
	(low, high, mid) = (1, k, 0)
	while low <= high:
		mid = (low + high) // 2
		s = range_sum(mid, k)
		if s == n:
			return k - mid + 1
		elif s > n:
			low = mid + 1
		else:
			high = mid - 1
	return k - low + 2
(n, k) = list(map(int, input().split(' ')))
if n == 1:
	print(0)
elif n <= k:
	print(1)
else:
	n -= 1
	k -= 1
	if n > sum(k):
		print(-1)
	else:
		print(binary_search(k, n))


def is_good(x, n, k):
	y = k - x + 1
	return y + k * (k - 1) // 2 - y * (y - 1) // 2 >= n
(n, k) = [int(x) for x in input().split()]
if n == 1:
	print(0)
elif k + (k - 2) * (k - 1) // 2 < n:
	print(-1)
elif k >= n:
	print(1)
else:
	l = 0
	r = k
	while r > l + 1:
		m = (l + r) // 2
		if is_good(m, n, k):
			r = m
		else:
			l = m
	print(r)


def sq(x):
	l = 0
	r = 10 ** 9 + 1
	while l + 1 < r:
		m = (l + r) // 2
		if m * (m + 1) // 2 <= x:
			l = m
		else:
			r = m
	return l

def s():
	[n, k] = list(map(int, input().split()))
	if k * (k - 1) // 2 + 1 < n:
		print(-1)
		return
	l = int(k * (k - 1) // 2) + 1 - n
	import math
	a = sq(l)
	print(k - 1 - a)
s()


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

def sum_range(n):
	return n * (n + 1) // 2

def bs(st, en):
	while st < en:
		mid = st + (en - st) // 2
		s1 = s - sum_range(mid - 1)
		if s1 == n:
			return k - mid + 1
		elif s1 > n:
			st = mid + 1
		else:
			en = mid
	return k - st + 2
(n, k) = inp()
n -= 1
k -= 1
s = sum_range(k)
if n + 1 == 1:
	print(0)
elif n <= k:
	exit(print(1))
elif n > s:
	print(-1)
else:
	print(bs(1, k))


(n, k) = input().split()
(n, k) = (int(n), int(k))
(ini, fin) = (1, k - 1)
if n == 1:
	print('0')
	exit(0)
if 1 + k * (k - 1) // 2 < n:
	print('-1')
	exit(0)
while ini < fin:
	mid = (ini + fin) // 2
	s = 1 + (k - 1) * mid - mid * (mid - 1) // 2
	if s >= n:
		fin = mid
	else:
		ini = mid + 1
print(ini)


from math import *
(n, k) = map(int, input().split(' '))
if n == 1:
	print(0)
	return
if k + 1 == n:
	print(2)
	return
if k >= n:
	print(1)
	return
d = (2 * k - 3) ** 2 + 8 * (k - n)
if d < 0:
	print(-1)
	return
if d == 0:
	x1 = (2 * k - 3) / 2
	if x1 < 0 or ceil(x1) > k - 2:
		print(-1)
	elif x1 == ceil(x1):
		print(x1 + 2)
	else:
		print(ceil(x1) + 1)
	return
x1 = (2 * k - 3 - sqrt(d)) / 2
x2 = (2 * k - 3 + sqrt(d)) / 2
if x1 <= 0:
	if x2 <= 0 or ceil(x2) > k - 2:
		print(-1)
	elif x1 == ceil(x1):
		print(x1 + 2)
	else:
		print(ceil(x1) + 1)
elif x1 <= 0 or ceil(x1) > k - 2:
	print(-1)
else:
	print(ceil(x1) + 1)


import sys

def f(m):
	if m - 1 < 0:
		return 0
	return (m - 1) * m // 2

def calc(m, K):
	rest = K - m
	return K + f(K - 1) - f(rest)

def __starting_point():
	(N, K) = list(map(int, input().split()))
	if N == 1:
		print(0)
		return
	if N <= K:
		print(1)
		return
	left = 0
	right = K + 1
	result = 10 ** 10
	while right - left > 1:
		med = (right + left) // 2
		res = N - calc(med, K)
		if res == 0:
			print(med)
			return
		if res > 0:
			rest = K - med - 1
			if rest >= res:
				result = min(result, med + 1)
			left = med
		else:
			right = med
	if result >= 10 ** 10:
		result = -1
	print(result)
__starting_point()


def reach_max(n, k):
	return n * k + 1 - n * (n + 1) // 2
(n, k) = map(int, input().split())
if n == 1:
	print(0)
	exit()
(lo, hi) = (1, k - 1)
if n > reach_max(hi, k):
	print(-1)
	exit()
while lo < hi:
	mid = (lo + hi) // 2
	if reach_max(mid, k) < n:
		lo = mid + 1
	else:
		hi = mid
print(lo)


import sys

def getSum(a):
	sum1 = a * (a + 1) // 2
	return sum1

def getSumOfTwo(a, b):
	if a <= 1:
		return getSum(b)
	return getSum(b) - getSum(a - 1)
(n, k) = [int(elem) for elem in input().split()]
if n == 1:
	print(0)
	sys.exit(0)
if n <= k:
	print(1)
	sys.exit(0)
if getSum(k - 1) < n - 1:
	print(-1)
	sys.exit(0)
n -= 1
k -= 1
(left, right) = (1, k)
while left < right:
	mid = (left + right) // 2
	sum1 = getSumOfTwo(mid, k)
	if sum1 == n:
		print(k - mid + 1)
		sys.exit(0)
	if sum1 > n:
		left = mid + 1
	else:
		right = mid
print(k - left + 2)


import math
from decimal import Decimal

def sum2(s, e):
	return sum1(e) - sum1(s - 1) - (e - s)

def sum1(i):
	return i * (i + 1) / 2
line = input().split()
n = Decimal(line[0])
k = Decimal(line[1])
if n == 1:
	print(0)
elif k > n:
	print(1)
elif sum2(Decimal(2), k) < n:
	print(-1)
else:
	c = 2 * n + k - k * k
	discriminant = (9 - 4 * c).sqrt()
	tmp = discriminant / 2
	const = Decimal(3 / 2)
	res1 = math.floor(const + tmp)
	res2 = math.floor(const - tmp)
	res1 = max(res1, res2)
	print(k - res1 + 1)


def findValue(n, m):
	return n * (n + 1) // 2 - m * (m + 1) // 2 - (n - m - 1)
(n, k) = map(int, input().split())
maxi = k * (k + 1) // 2 - k + 1
if n == 1:
	print(0)
elif n > maxi:
	print(-1)
else:
	begin = 2
	end = k
	while begin <= end:
		mid = (begin + end) // 2
		value = findValue(k, mid)
		if value == n:
			MID = mid
			break
		elif value > n:
			begin = mid + 1
		else:
			MID = mid
			end = mid - 1
	remaining = n - findValue(k, MID)
	if remaining == 0:
		print(k - MID)
	else:
		print(k - MID + 1)


R = lambda : map(int, input().split())
(n, k) = R()
if n == 1:
	print(0)
	return
if 1 + k * (k - 1) // 2 < n:
	print(-1)
	return
(l, r) = (0, k - 1)
while l < r:
	m = (l + r + 1) // 2
	if 1 + (m + k - 1) * (k - 1 - m + 1) // 2 >= n:
		l = m
	else:
		r = m - 1
if 1 + (l + k - 1) * (k - 1 - l + 1) // 2 < n:
	print(k - 1 - l + 2)
else:
	print(k - 1 - l + 1)


import sys
input = sys.stdin.readline

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

def sum(n, r):
	return n * (2 * r - (n - 1)) // 2

def function(total, l, r):
	left = l
	right = r
	while left <= right:
		mid = (right + left) // 2
		result = sum(r - mid + 1, r)
		if result == total:
			return r - mid + 1
		elif result > total:
			left = mid + 1
		elif sum(r - mid + 2, r) > total:
			return r - mid + 2
		else:
			right = mid - 1
	return -1
(n, m) = multi_input()
n = n - 1
m = m - 1
if n == 0:
	print(0)
elif sum(m, m) < n:
	print(-1)
elif m < n:
	print(function(n, 1, m))
else:
	print(1)


def f(x):
	return x * (x + 1) // 2

def works(n, k, s):
	rem = k - 1 - s
	val = f(k - 1) - f(rem) + 1
	return val >= n

def main():
	(n, k) = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif not works(n, k, k):
		print(-1)
	else:
		lo = 0
		hi = k
		while lo + 1 < hi:
			mid = (lo + hi) // 2
			if works(n, k, mid):
				hi = mid
			else:
				lo = mid
		print(hi)
main()


import math
from decimal import Decimal, ROUND_FLOOR

def sum2(s, e):
	return sum1(e) - sum1(s - 1) - (e - s)

def sum1(i):
	return i * (i + 1) / 2
(n, k) = map(Decimal, input().split())
if n == 1:
	print(0)
elif k > n:
	print(1)
elif sum2(Decimal(2), k) < n:
	print(-1)
else:
	c = 2 * n + k - k * k
	discriminant = (9 - 4 * c).sqrt()
	res1 = int(((3 + discriminant) / 2).to_integral_exact(rounding=ROUND_FLOOR))
	res2 = int(((3 - discriminant) / 2).to_integral_exact(rounding=ROUND_FLOOR))
	res1 = max(res1, res2)
	print(k - res1 + 1)


import sys
import math

def readlines(type=int):
	return list(map(type, sys.stdin.readline().split()))

def read(type=int):
	return type(sys.stdin.readline().strip())
joint = lambda it, sep=' ': sep.join([str(i) if type(i) != list else sep.join(map(str, i)) for i in it])

def solve_naive(n, k):
	taken = set()
	current_cap = 0
	found = False
	while current_cap != n:
		for c in range(k, 1, -1):
			found = False
			if current_cap == 0:
				if c <= n:
					current_cap += c
					taken.add(c)
					found = True
					break
			elif c not in taken and c - 1 <= n - current_cap:
				current_cap += c - 1
				taken.add(c)
				found = True
				break
		if not found:
			break
	return len(taken) if found else -1

def solve(n, k):
	if n == 1:
		return 0
	if k >= n:
		return 1
	else:
		if (3 - 2 * k) ** 2 - 8 * (n - k) < 0:
			return -1
		t = (-math.sqrt((3 - 2 * k) ** 2 - 8 * (n - k)) + 2 * k - 3) / 2
		if t == 0.0:
			return 2
		if t % 1 == 0:
			return 1 + int(t)
		else:
			return 2 + int(t)

def main():
	(n, k) = readlines()
	print(solve(n, k))
main()


import decimal
(n, k) = input().split(' ')
n = int(n)
k = int(k)
coef1 = (k * k - k - 2 * n) * 100 + 225
if coef1 < 0:
	print('-1')
else:
	D = decimal.Decimal
	coef11 = D(coef1)
	coef1 = coef11.sqrt()
	coef2 = k * 10 - 5
	coef = (coef2 - coef1) / 10
	if coef % 1 == 0:
		print(int(coef))
	else:
		print(int(coef) + 1)


(n, k) = map(int, input().split())

def prod(n):
	if n % 2:
		return n * ((n + 1) // 2)
	else:
		return n // 2 * (n + 1)

def total_count(n, k):
	if k >= n:
		return (0, 0, 1)
	else:
		count = 0
		l = 1
		r = k
		s = prod(k)
		while l <= r:
			mid = (l + r) // 2
			if n > s - prod(mid) + mid:
				r = mid - 1
			else:
				l = mid + 1
		n = n - (s - prod(l) + l)
		count += k - l + 1
		k = l - 1
		return (n, k, count)
if prod(k) - (k - 1) < n:
	print(-1)
elif n == 1:
	print(0)
elif k >= n:
	print(1)
else:
	n = n - k
	k = k - 2
	count = 1
	while n > 0:
		(n, k, temp) = total_count(n, k)
		count += temp
	print(count)


def sm(n):
	return int(int(n * (n + 1)) / int(2))

def summ(en, st):
	if st <= 1:
		return sm(en)
	return sm(en) - sm(st - 1)

def bs(n, k):
	st = 1
	en = k
	while st < en:
		md = int(int(st + en) / int(2))
		s = summ(k, md)
		if s == n:
			return k - md + 1
		elif s > n:
			st = md + 1
		else:
			en = md
	return k - st + 2
(n, k) = input().split()
n = int(n)
k = int(k)
if n == 1:
	print(0)
elif n <= k:
	print(1)
else:
	n -= 1
	k -= 1
	if sm(k) < n:
		print(-1)
	else:
		print(int(bs(n, k)))


def lower_bound(n, k):
	low = 1
	high = k
	while low < high:
		mid = low + (high - low) // 2
		pipes = mid * k - (mid + 2) * (mid - 1) // 2
		if pipes >= n:
			high = mid
		else:
			low = mid + 1
	return low

def main():
	(n, k) = map(int, input().split())
	if n == 1:
		print(0)
	else:
		ans = lower_bound(n, k)
		if ans == k:
			print(-1)
		else:
			print(ans)
main()


def valid(k, mid):
	return (2 * k - mid - 1) * mid // 2 + 1

def binary_search(n, k):
	(l, r) = (0, k - 1)
	while l <= r:
		mid = l + r >> 1
		if valid(k, mid) < n:
			l = mid + 1
		else:
			r = mid - 1
	return l

def main():
	(n, k) = map(int, input().split())
	res = binary_search(n, k)
	print(-1 if res == k else res)
main()


def normal_sum(N):
	return (N ** 2 + N) // 2

def sum(i, j):
	return normal_sum(j) - 1 - (normal_sum(i - 1) - 1)

def bs_sum(start, end, k, n):
	mid = (start + end) // 2
	if n - sum(mid, k) >= mid:
		return bs_sum(start, mid - 1, k, n)
	if n - sum(mid, k) < 0:
		return bs_sum(mid + 1, end, k, n)
	return k - mid + 2 if n - sum(mid, k) != 0 else k - mid + 1
(n, k) = [int(n) for n in input().split()]
if n == 1:
	print(0)
elif n <= k:
	print(1)
elif normal_sum(k) - 1 - (k - 2) < n:
	print(-1)
else:
	n -= 1
	k -= 1
	answer = bs_sum(1, k, k, n)
	print(answer)


def sum_1(n):
	s = n * (n + 1) // 2
	return s

def sum_2(s, e):
	if s <= 1:
		return sum_1(e)
	return sum_1(e) - sum_1(s - 1)

def mini_splitter(k, n):
	st = 1
	end = k
	while st < end:
		mid = (st + end) // 2
		s = sum_2(mid, k)
		if s == n:
			return k - mid + 1
		elif s > n:
			st = mid + 1
		else:
			end = mid
	return k - st + 2
(n, k) = map(int, input().split())
if n == 1:
	print('0')
elif n <= k:
	print('1')
else:
	k -= 1
	n -= 1
	if sum_1(k) < n:
		print('-1')
	else:
		print(mini_splitter(k, n))


def valid(number_to_check, n, k):
	sum = 1
	sum = sum + k * (k - 1) // 2 - (k - number_to_check) * (k - number_to_check - 1) // 2
	if sum >= n:
		return True
	return False

def binary_serach(n, k):
	lo = 1
	hi = k
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if valid(mid, n, k):
			hi = mid
		else:
			lo = mid + 1
	if valid(lo, n, k):
		return lo
	else:
		return -1
(n, k) = map(int, input().split())
if n == 1:
	print(0)
elif n <= k:
	print(1)
else:
	print(binary_serach(int(n), int(k)))


def bs(n, k, lo, hi):
	while lo <= hi:
		mid = (hi + lo) // 2
		summ = k * (k + 1) // 2 - 1 - ((mid - 1) * mid // 2 - 1) - (k - 2)
		if summ == n:
			return k - mid + 1
		if summ > n:
			lo = mid + 1
		elif summ < n:
			hi = mid - 1
	if summ > n:
		mid += 1
	return k - mid + 1

def solve():
	(n, k) = map(int, input().split())
	if n == 1:
		return 0
	elif k * (k + 1) // 2 - (k - 2) <= n:
		return -1
	elif k >= n:
		return 1
	else:
		return bs(n, k, 2, k)
print(solve())


(n, k) = list(map(int, input().split()))
start = k - 1
end = 1

def bsearch(start, end):
	if start < end:
		return start
	else:
		mid = start - (start - end) // 2
		val = (k - 1) * k // 2 - (mid - 1) * mid // 2 + 1
		if val == n:
			return mid
		elif val > n:
			end = mid + 1
		else:
			start = mid - 1
		return bsearch(start, end)
ans = bsearch(start, end)
if ans == 0:
	print(-1)
elif n == 1:
	print(0)
else:
	print(k - ans)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def getSum(p, q):
	n = q - p + 1
	temp = n * (p + q) // 2 - n + 1
	return (temp, n)

def main():
	(n, k) = invr()
	l = 2
	r = k
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		(tot, count) = getSum(mid, k)
		if tot >= n:
			ans = count
		if tot < n:
			r = mid - 1
		else:
			l = mid + 1
	if n == 1:
		ans = 0
	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))

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


import sys
from collections import OrderedDict

def sum_from_two(x):
	return x * (x + 1) // 2 - 1

def sum_last(k, x):
	if x == 0:
		return 1
	return sum_from_two(k) - sum_from_two(k - x) - x + 1

def possible(n, k, x):
	return sum_last(k, x) >= n

def main(n, k):
	if n == 1:
		return 0
	if sum_last(k, k - 1) < n:
		return -1
	minimum = 1
	maximum = k - 1
	while minimum <= maximum:
		if minimum == maximum:
			return minimum
		elif minimum == maximum - 1:
			if possible(n, k, minimum):
				return minimum
			else:
				return maximum
		mid = (minimum + maximum) // 2
		if possible(n, k, mid):
			maximum = mid
		else:
			minimum = mid
curr = None
for (e, line) in enumerate(sys.stdin.readlines()):
	(n, k) = list(map(int, line.strip().split()))
print(main(n, k))


(casas, tubos) = map(int, input().strip().split())

def bs(c, t):
	(l, r) = (0, t - 1)
	while l <= r:
		mid = l + r >> 1
		if (2 * t - mid - 1) * mid // 2 + 1 < c:
			l = mid + 1
		else:
			r = mid - 1
	return r + 1
res = bs(casas, tubos)
print(-1 if res == tubos else res)


from sys import stdin

def solve(tc):
	(n, k) = map(int, stdin.readline().split())
	if n == 1:
		print(0)
		return
	if n <= k:
		print(1)
		return
	(lo, hi) = (1, k - 1)
	while lo < hi:
		mid = lo + (hi - lo + 1) // 2
		cum = (k - 2 + mid - 1) * (k - mid) // 2
		if cum < n - k:
			hi = mid - 1
		else:
			lo = mid
	if lo == 1:
		print(-1)
		return
	print(k - lo + 1)
tcs = 1
for tc in range(tcs):
	solve(tc)


(n, k) = map(int, input().split())
if n == 1:
	print(0)
elif (k * k - k) // 2 + 1 < n:
	print(-1)
else:
	(g, b) = (0, k // 2)
	while b != 0:
		while g + b <= k and (k * k - k) // 2 + 1 - ((g + b) ** 2 - (g + b)) // 2 >= n:
			g += b
		b //= 2
	print(k - g)


(n, k) = list(map(int, input().split()))
(l, h) = (int(-1), k + 1)
while l + 1 < h:
	mid = (l + h) // 2
	val = (k - mid + 1 + k) * mid // 2 - (mid - 1)
	if val < n:
		l = mid
	else:
		h = mid
print(-1 if h == k + 1 else h)


def bin_search(n):
	if n == 1:
		return 1
	l = 0
	r = n
	while r - 1 > l:
		mid = (l + r) // 2
		val = mid * (mid + 1) // 2
		if val == n:
			return mid
		elif val > n:
			r = mid
		else:
			l = mid
	return l
(n, k) = [int(i) for i in input().split()]
if k * (k - 1) // 2 < n - 1:
	print(-1)
elif n == 1:
	print(0)
elif n <= k:
	print(1)
else:
	print(k - 1 - bin_search(k * (k - 1) // 2 - n + 1))


def s(n):
	return n * (n + 1) // 2

def diff(st, en):
	return s(en) - s(st - 1)

def bs(k, n):
	st = 1
	en = k
	while st < en:
		mid = (st + en) // 2
		sum = diff(mid, k)
		if sum == n:
			return k - mid + 1
		if sum > n:
			st = mid + 1
		else:
			en = mid
	return k - st + 2
(n, k) = map(int, input().split())
if n == 1:
	print(0)
elif n <= k:
	print(1)
else:
	n -= 1
	k -= 1
	if s(k) < n:
		print(-1)
	else:
		print(bs(k, n))


def suma(n):
	return n * (n + 1) // 2

def sumaij(i, j):
	if i <= 1:
		return suma(j)
	return suma(j) - suma(i - 1)

def bin_search_solution(n, k):
	(st, end) = (1, k)
	while st < end:
		mid = (st + end) // 2
		s = sumaij(mid, k)
		if s == n:
			return k - mid + 1
		if s > n:
			st = mid + 1
		else:
			end = mid
	return k - st + 2

def solve():
	(n, k) = map(int, input().split())
	if n == 1:
		print(0)
	elif k >= n:
		print(1)
	else:
		n -= 1
		k -= 1
		if suma(k) < n:
			print(-1)
		else:
			res = bin_search_solution(n, k)
			print(res)
solve()