Олимпиадный тренинг

Задача 38847. Cinema


Marya Ivanovna and Marya Mikhailovna led the schoolchildren to the cinema. So that there would be no offense, Marya Ivanovna lined up all the schoolchildren in alphabetical order and seated them: first in the first row from left to right, then in the second from left to right, etc., filling the entire hall of n rows of m seats. Then Marya Mikhailovna came and said that the guys sat down incorrectly – need to transfer. She suggested first filling all the first places from the first row to the last, then all the second places, and so on.

Determine how many schoolchildren will remain in their place after such a transplant.

For example, if n = 3 and m = 3, then in the first case the children will sit like this:

1    2    3
4    5    6
7    8    9
and in the second – like this:
1    4    7
2    5    8
3    6    9
Thus, three students: 1, 5 and 9 will remain in their places.

Input
Enter two integers n and m (1 ≤ n, m ≤ 109 ).

Imprint
Output the number of schoolchildren who will remain in their places.
 
Examples
# Input Output
1 3 3 3
2 2 4 2