R=range def J(): return map(int,input().split()) L,N=J() X=[0]+list(J())+[L] A=[{0},set()] E={X[1]} for i in R(2,N+2): A+=[A[-1]|E] E={x+X[i]-X[j]for j in R(i)for x in A[j]} print(min(abs(x*2-L)for x in A[-1]))