KUSAC - Kusac

Mirko has given up on the difficult coach job and switched to food tasting instead. Having skipped breakfast like a professional connoisseur, he is visiting a Croatian cured meat festival. The most renowned cook at the festival, Marijan Bajs, has prepared N equal sausages which need to be distributed to M tasters such that each taster gets a precisely equal amount. He will use his trusted knife to cut them into pieces.

In order to elegantly divide the sausages, the number of cuts splitting individual sausages must be as small as possible. For instance, if there are two sausages and six tasters (the first test case below), it is sufficient to split each sausage into three equal parts, making a total of four cuts. On the other hand, if there are three sausages and four tasters (the second test case below), one possibility is cutting off three quarters of each sausage. Those larger parts will each go to one of the tasters, while the fourth taster will get the three smaller pieces (quarters) left over.

Mirko wants to try the famous sausages, so he volunteered to help Bajs. Help them calculate the minimum total number of cuts needed to carry out the desired division.

Input

The first and only line of input contains two positive integers, N and M (1 ≤ N, M ≤ 100), the number of sausages and tasters, respectively.

Output

The first and only line of output must contain the required minimum number of cuts.

Example

Input:
2 6

Output:
4
Input:
3 4

Output:
3
Input:
6 2

Output:
0

Added by:Tomislav Babic
Date:2013-10-05
Time limit:0.109s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:COCI 2013 1. round

hide comments
2014-06-17 12:38:00 Francky
According to forum there's a curious issue. I've email admins for that. I send a mail to psetter too. Let's see.
2014-06-17 12:38:00 Aman Tripathi
Something wrong with test file #8.
assert(n>=1 && n<=100 && m>=1 && m<=100) gives Runtime Error.
Also printing 0 for (n<=0 or m<=0) gives WA on file #8

Last edit: 2014-05-15 20:15:46
2014-06-17 12:38:00 Petar Bosnjak
since when O(10000) is too slow for 1 sec?
2014-06-17 12:38:00 SanchitK
some test cases
6 4
2
12 30
24
12 8
4
2014-06-17 12:38:00 Nitin Kapoor
found the error . got AC.

Last edit: 2014-01-22 22:24:29
2014-06-17 12:38:00 sankar
Great question :)
2014-06-17 12:38:00 Bhavik
very very good question:))
2014-06-17 12:38:00 NIK
Fooh...100th
2014-06-17 12:38:00 Decode
Plz give any tricky test cases.
2014-06-17 12:38:00 Gourav Saha
i am getting wa in 8th test case can you please check my submission id 10297137????
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.