k,n=list(map(int,input().split()))

a=list(map(int,input().split()))

ma=0

for i in range(n-1):

    ma=max(ma,a[i+1]-a[i])

print((k-max(ma,a[0]+k-a[n-1])))
k,n=list(map(int,input().split()))

a=list(map(int,input().split()))



check_l =[]

for i in range(len(a)-1):

	check_l.append(a[i+1]-a[i])



check_l.append(k+a[0]-a[n-1])

print((k-max(check_l)))
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
ma = 0
for i in range(n - 1):
    ma = max(ma, a[i + 1] - a[i])
print((k - max(ma, a[0] + k - a[n - 1])))

k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
check_l = []
for i in range(len(a) - 1):
    check_l.append(a[i + 1] - a[i])
check_l.append(k + a[0] - a[n - 1])
print((k - max(check_l)))

-ma = 0 -for i in range(n - 1): -    ma = max(ma, a[i + 1] - a[i]) -print((k - max(ma, a[0] + k - a[n - 1]))) +check_l = [] +for i in range(len(a) - 1): +    check_l.append(a[i + 1] - a[i]) +check_l.append(k + a[0] - a[n - 1]) +print((k - max(check_l)))