Codeforces Round 558 (Div. 2)
A
Eating Soup
Codeforces
900
原题
←B1 →
翻译中…

The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...

翻译中…

What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $n$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.

翻译中…

Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $m$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?

翻译中…

Could you help her with this curiosity?

翻译中…

You can see the examples and their descriptions with pictures in the "Note" section.

翻译中…

Input

翻译中…

The only line contains two integers $n$ and $m$ ($2 \leq n \leq 1000$, $0 \leq m \leq n$) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.

翻译中…

Output

翻译中…

Print a single integer — the maximum number of groups of cats at the moment Katie observes.

翻译中…

Note

翻译中…

In the first example, originally there are $7$ cats sitting as shown below, creating a single group:

翻译中…

image

翻译中…

At the observed moment, $4$ cats have left the table. Suppose the cats $2$, $3$, $5$ and $7$ have left, then there are $3$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.

翻译中…

image

翻译中…

In the second example, there are $6$ cats sitting as shown below:

翻译中…

image

翻译中…

At the observed moment, $2$ cats have left the table. Suppose the cats numbered $3$ and $6$ left, then there will be $2$ groups remaining ($\{1, 2\}$ and $\{4, 5\}$). It is impossible to have more than $2$ groups of cats remaining.

翻译中…

image

翻译中…

In the third example, no cats have left, so there is $1$ group consisting of all cats.

翻译中…

In the fourth example, all cats have left the circle, so there are $0$ groups.

翻译中…

样例

Input #1
7 4
Output #1
3
InputCopy OutputCopy
Input #2
6 2
Output #2
2
InputCopy OutputCopy
Input #3
3 0
Output #3
1
InputCopy OutputCopy
Input #4
2 2
Output #4
0
InputCopy OutputCopy
题目信息
题号
1163A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。