L, N = map(int, input().split()) X = list(map(int, input().split())) + [L] Q = [{X[0]}, set()] now = X[0] for x in X[1:]: dif = x - now Q2 = [set(), set()] for j in range(2): for q in Q[j]: Q2[0].add(q + dif) Q2[1].add(q - dif) now = x Q = Q2 ans = 10 ** 10 for q in Q[1]: ans = min(ans, abs(q)) print(ans)