Skip to content
AlgoArena

Chocolate bar

Medium 1 s 256 MBmath

Brothers are always arguing. Even the smallest things are very important to them.

One day, Grandpa Husan brought a chocolate bar for his two grandchildren. Now he needs to divide the chocolate between them as equally as possible. Otherwise, the grandchildren are sure to start fighting with each other.

Initially, the chocolate bar is a rectangle of size (M x N). Thus, the chocolate bar consists of (MN) unit squares. Each time, Grandpa Husan makes a cut along a straight line across the chocolate bar and gives one of the resulting pieces to either of his two grandchildren.

What is the minimum number of cuts Grandpa Husan needs to make to achieve his goal?

Input

A single line contains two integers, M and N (1 ≤ M, N ≤ 106) — the dimensions of the original chocolate bar.

Output

The minimum number of cuts required for Grandpa Husan to divide the chocolate as fairly as possible.

Examples

Input 1
3 3
Output 1
2

Explanation

ch

Input 2
4 6
Output 2
1