Sabzeh with Lentils
View as PDFParsa's Grandmother has prepared a row of planting positions, numbered from
to
.
She wants to plant exactly
lentil seeds in these positions.
At most one seed can be planted in each position.
If two consecutive positions both contain a seed, that creates one adjacent occupied pair.
Grandmother wants to place the seeds so that the number of adjacent occupied pairs is as small as possible.
Compute this minimum possible number.
Input
The input contains two integers, the number of positions and
, the number of lentil seeds.
Output
Print a single integer: the minimum possible number of adjacent occupied pairs.
Constraints
Example 1
Input
5 2
Output
0
Example 2
Input
5 4
Output
2
Comments