COMFORT | 프로그래밍의 벗 PivotOJ
PivotOJ

COMFORT

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2002 National Competition #1 - JuniorsBOJ 3258

문제

A game-board consists of N fields placed around a circle. Fields are successively numbered from1 to N clockwise. On some of the fields there are obstacles.

Player starts on a field marked with number 1. His goal is to reach a given field marked with number Z using only moves consisting of clockwise jumps of length K. The player’s path should not contain any of the fields having an obstacle.

For example, if N=13, K=3 and Z=9, the player can jump across the fields 1, 4, 7, 10, 13, 3, 6 and 9, reaching his goal under condition that none of these fields has an obstacle on it.

Your task is to write a program that finds the smallest possible number K.

입력

First line of the input file consists of integers N, Z and M, 2 ≤ N ≤ 1000, 2 ≤ Z, 0 ≤ M ≤ N-2.

N represents number of fields on the game-board and Z is a given goal-field.

Next line consists of M different integers that represent marks of fields having an obstacle. Fields marked 1 and Z do not contain an obstacle. 

출력

The first and only line of the output file should contain requested number K defined above. 

예제

예제 1

입력
7 4 1
6
출력
1

예제 2

입력
9 7 2
2 3
출력
3

예제 3

입력
7 6 2
2 4
출력
5
코드를 제출하려면 로그인하세요.