cho.sh
Notes
Loading...

Cutting Chocolate

Time limit

2s

Memory limit

128 MB

Problem

Junghwa has one N×MN \times MN×M chocolate bar. The bar has grooves running horizontally and vertically, so if every groove is cut, it can be split into N×MN \times MN×M pieces of size 1×11 \times 11×1.

She wants to split the chocolate into 1×11 \times 11×1 pieces to share it with her friends. In one cut, she chooses one current chocolate piece and cuts it along one of its grooves. That piece then becomes two pieces.

Because the chocolate may melt while being cut, Junghwa wants to minimize the number of cuts. Given NNN and MMM, find the minimum number of cuts needed to make every piece have size 1×11 \times 11×1.

Input

The first line contains two integers NNN and MMM. (1≤N,M≤300)(1 \le N, M \le 300)(1≤N,M≤300)

Output

Print the minimum number of cuts needed to split the whole chocolate bar into 1×11 \times 11×1 pieces.