Cutting Chocolate

Interview

Time limit2sMemory limit128 MB

Summary
Compute the minimum number of straight cuts needed to divide an N by M chocolate bar into all 1x1 pieces.
Level

Easy1 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Junghwa has one N×MN \times 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 M pieces of size 1×11 \times 1.

She wants to split the chocolate into 1×11 \times 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 NN and MM, find the minimum number of cuts needed to make every piece have size 1×11 \times 1.

Input

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

Output

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

Examples2

  1. Example 1

    Input
    2 2
    
    Expected output
    3
    
  2. Example 2

    Input
    1 1
    
    Expected output
    0