Under construction

Still being built. Things may change

Big Round Table

Time limit1sMemory limit512 MB

Summary
Masha sits at a round table of n seats and makes exactly k swaps with a left or right neighbor; count the seats she could occupy at the end.
Level

Easy3 of 10

Topics
Math, Greedy, Implementation
Solved
No attempts yet

Problem

Today Masha is hosting guests. Including Masha, nn people take part in the celebration and sit in a circle at a big round table.

Masha wants to talk with many guests, of course, but shouting across the whole table is inconvenient. So she quickly came up with a solution: sometimes she asks the neighbor on her left or on her right to swap places with her. The guests gladly agree to her request, of course.

After seeing the guests off, Masha remembered that she left her phone at the seat where she was sitting at the end of the event. Masha does not remember which seat she sat in at the end, but she does remember which seat she sat in at the beginning, and she also remembers that she swapped places with one of her neighbors exactly kk times. Now she wants to know the number of seats where she could have ended up at the end of the evening.

Input

The input contains two positive integers nn and kk: the number of seats at the table and the number of times Masha swapped places with one of her neighbors (3≤n≤1093 \le n \le 10^9, 0≤k≤1090 \le k \le 10^9).

Output

Print a single number: the number of seats where Masha could have ended up at the end of the event.

Hint

In the first example, after swapping places with one of her neighbors twice, Masha could end up either at her original seat or at one of the two seats located one seat away from the original one.

In the second example, Masha could end up at any seat.

Examples2

  1. Example 1

    Input
    5 2
    
    Expected output
    3
    
  2. Example 2

    Input
    3 3
    
    Expected output
    3