Constraints not followed by the question


#1

It is given that N, M will at least be 1 in the question constraint.
However, one of the test cases tests on these being 0.
If not handled, it gives TLE or wrong answer.
try the case,
1 0
2