#C2919. Minimum Turns on a Grid
Minimum Turns on a Grid
Minimum Turns on a Grid
You are given a grid with ( n ) rows and ( m ) columns. The starting point is at the top-left corner ( (1, 1) ) and the destination is at the bottom-right corner ( (n, m) ). You can only move either right or down. A turn is defined as a change in direction (from moving right to moving down, or vice versa).
To minimize the number of turns, you should make as long stretches as possible in one direction. The formula to compute the minimum number of turns is:
[
\text{Minimum Turns} = \min(n, m) - 1
]
If one of the dimensions is 1, then no turn is needed.
inputFormat
The input consists of two space-separated integers, ( n ) and ( m ), where ( 1 \le n, m \le 10^6 ).
outputFormat
Output a single integer representing the minimum number of turns required to go from ( (1, 1) ) to ( (n, m) ).## sample
2 3
1
</p>