Chase That Cow
Farmer John knows the position of a cow and wants to catch it.
The farmer and the cow are located on the number line. The farmer starts at point N, and the cow is at point K.
The farmer has two ways to move:
- Move from X to X-1 or X+1, each move takes 1 minute.
- Move from X to 2*X, each move takes 1 minute.
Assume the cow is unaware of the farmer's actions and stays still.
What is the minimum time for the farmer to catch the cow?
Input format
One line containing two integers N and K.
Output format
Output an integer, the minimum time taken to catch the cow.
Data range
0 ≤ N, K ≤ 105
Sample input
5 17
Sample output
4
Comments