PivotOJ

Social Distancing

시간 제한: 1000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2021BOJ 24753

문제

It's time for a social distancing party! A group of friends are sitting around a circular table where some seats are filled and some seats are empty. In particular, to maintain social distancing protocols, no two people are sitting directly beside each other.

They want to expand the party and include more friends, but no one is willing to move out of their current seat. Given the current table seating, determine the maximum number of additional people that can be seated such that there is still at least one empty seat between all pairs of people seated.

입력

The first line of input contains two integers SS (3S10003 \leq S \leq 1\,000), which is the number of seats at the table, and NN (1NS/21 \leq N \leq S/2), which is the number of people that are already seated at the table.

Note that the seats of the table are numbered 1,2,,S1, 2, \ldots, S in a circular fashion: for each 1i<S1 \leq i < S, seats numbered ii and i+1i+1 are directly beside each other. Seats SS and 11 are also directly beside each other.

The second line contains NN integers a1,a2,,aNa_1, a_2, \ldots, a_N (1a1<a2<<aNS1 \leq a_1 < a_2 < \cdots < a_N \leq S), which indicates that seat number aia_{i} is currently occupied. No two occupied seats are directly beside each other.

출력

Display the maximum number of additional friends that can be seated at the table such that there is still at least one empty seat between all pairs of people seated.

예제

예제 1

입력
9 2
2 6
출력
2

예제 2

입력
10 3
1 4 7
출력
1

예제 3

입력
6 2
2 5
출력
0

예제 4

입력
100 5
7 14 47 78 99
출력
43

예제 5

입력
6 1
3
출력
2
코드를 제출하려면 로그인하세요.