시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 9 6 6 66.667%

문제

원 모양으로 나열된 N개의 필드를 가진 게임판이 있다. 각 필드는 1~N까지 시계방향으로 숫자가 매겨져 있다. 몇개의 필드에는 장애물이 놓여져 있다.

아람이는 1에서 게임을 시작한다. Z번째 필드에 도착하는 것이 이 게임의 목표이다. 도착점은 K만큼씩 시계방향으로 이동해 도달해야 한다. 도착점으로 가는 길에 장애물이 있는 필드를 밟아서는 안된다.

예를들어 N=13 K=3 그리고 Z=9라고 했을 때 아람이는 1,4,7,10,13,3,6 그리고 9 의 필드를 지나게 된다. 도착점으로 가는 경로 중 장애물이 있는 필드가 하나라도 있으면 안 된다.

게임판의 정보가 주어졌을 때 도착점에 도착할 수 있는 가장 작은 K를 찾는 프로그램을 작성하시오.

입력

입력의 첫째줄에는 N(2≤N≤1000) , Z(2≤Z), M(0≤<M≤N-2) 이 주어진다.

N은 필드의 수이고 Z는 도착해야하는 필드의 번호를 의미한다.

다음 M개의 줄에는 서로 다른 정수가 주어진다. 이 정수는 장애물이 있는 필드의 번호를 나타낸다.

1번과 Z번째 필드에는 장애물이 놓이지 않는다.

출력

출력의 첫번째 줄에 위에서 정의되어진 K를 출력한다.

예제 입력 1

7 4 1
6

예제 출력 1

1

예제 입력 2

9 7 2
2 3

예제 출력 2

3

예제 입력 3

7 6 2
2 4

예제 출력 3

5
W3sicHJvYmxlbV9pZCI6IjMyNTgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWNlZjRcdWQzZWNcdWQyYjgiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzZkMCBcdWJhYThcdWM1OTFcdWM3M2NcdWI4NWMgXHViMDk4XHVjNWY0XHViNDFjIE5cdWFjMWNcdWM3NTggXHVkNTQ0XHViNGRjXHViOTdjIFx1YWMwMFx1YzljNCBcdWFjOGNcdWM3ODRcdWQzMTBcdWM3NzQgXHVjNzg4XHViMmU0LiBcdWFjMDEgXHVkNT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