Problem: There are K lemurs on Madagascar and Kevin has N bananas. He has to give away all his bananas to lemurs. Lemurs are happy if all of them get the same number of bananas (even if they don't get any). In one minute Kevin can do one of the following:
 Find one banana. 
 Discard one banana (eat). 
 Increase a population of lemurs on Madagascar by one. 
 If there are at least two lemurs remove one of them from Madagascar (don't ask how). 

Help Kevin and find the minimum number of minutes Kevin needs to satisfy all the lemurs.

Input format:

The only line of the input contains two space-separated integers N and K.

Output format:

Output the single integer -- the minimum number of minutes.

Constraints:
1 ≤ K,N ≤ 10^5
K, N ≤ 50 in test data worth 33% of all points

SAMPLE INPUT
47 17

SAMPLE OUTPUT
2

Solution (in PYTHON):

Solution:
def step_required(big, small):
	mod = big % small
	if float(small) / 2 >= mod:
		return small - mod
	else:
		return mod

def find_minimum_steps(n, k):
	res = 10**9
	# if n = 47, k = 17
	# by increasing by 1 or decreasing by 1 maximum cases are 34. so traversing from 1 to 34.
	# abs(k - i) i.e. to increase or dec number of steps required.
	# min(n % i , i - n % i), we increase/dec k by i we must need to inc or dec value by mod value.
	# so number_of_steps required = abs(k - i) + min(n % i , i - n % i)
	# for everycase we will check minimum steps.
	for i in range(1, 2 * k+1):
		res = min( res, abs(k - i) + min(n % i , i - n % i) )
	return res


if __name__ == '__main__':
	n, k = map(int, raw_input().split(" "))
	print find_minimum_steps(n, k)