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: interview

Starter code:

Solutions:
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())
m = 2 * (n - 1) - k * (k - 1)
if m > 0: print(-1)
else:
    x = int((1 + (1 - 4 * m) ** 0.5) / 2)
    if x * (x - 1) + m > 0: x -= 1
    print(k - x)

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)
    if x * (x - 1) + m > 0: x -= 1
    print(k - x)

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)
    else:
        if (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)
    else:
        if (x1 == ceil(x1)):
            print(x1+2)
        else:
            print(ceil(x1)+1)
else:
    if x1 <= 0 or ceil(x1) > k-2:
        print(-1)
    else:
        print(ceil(x1)+1)

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


# 0 1 2  3  4  5
# 1 2 4  7 11 16

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


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

l, r = int(-1), k+1
while l+1 < r:
	mid = (l+r) // 2
	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)

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

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 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 r+1

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

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 = list(map(int, input().split()))
    res = binary_search(n, k)
    print(-1 if res == k else res)

main()


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

    if x * (x - 1) + m > 0: x -= 1

    print(k - x)



# Made By Mostafa_Khaled


import sys

n,k = map(int, input().split())
k -= 1
lo,hi = 0,int(1e9)
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)

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)

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 reach_max(n, k):
    return n * k + 1 - n * (n + 1) // 2


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

if n == 1:
    print(0)
    return

lo, hi = 1, k - 1

if n > reach_max(hi, k):
    print(-1)
    return


while lo < hi:
    mid = (lo + hi) // 2
    if reach_max(mid, k) < n:
        lo = mid + 1
    else:
        hi = mid

print(lo)


import math
from decimal import Decimal

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

def sum1(i):
    return i * (i + 1) / 2

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

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()
    res1 = math.floor((3 + discriminant) / 2)
    res2 = math.floor((3 - discriminant) / 2)
    res1 = max(res1, res2)
    print(int(k - res1 + 1));

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

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 = math.floor((3 + discriminant) / 2)
    res2 = math.floor((3 - discriminant) / 2)
    res1 = max(res1, res2)
    print(k - res1 + 1);

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

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

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


n,k=list(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
	#print(g,m*(m+1)//2,n,l,r)
	if (g-m*(m+1)//2)>=n:
		ans=k-m
		l=m+1
	else:
		r=m-1
print(ans)