Kid’s Simple Puzzle Problem

Kid’s are playing a tiling game. First they draw an N ×M rectangle with N rows and M columns (N ∗M squares), then they try to cover it completely with the 2 wooden pieces shown in the figure at the right (left piece covers 4 squares, while right piece covers 3). Note that the pieces can be rotated or flipped. Com- pute the minimum number of puzzle pieces required, or output ‘-1’ if it’s not possible. Input A number of of inputs (≤ 1000), each starting with n, m (1 ≤ n,m ≤ 1000000000) on a line. Output For each input, output the minimum number of puzzle pieces, or ‘-1’ if it’s not possible. Sample Input 11 23 Sample Output -1 2