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

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

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

counter = 0



for i in range(n):

  if counter < a[i+1]-a[i]:

    counter = a[i+1]-a[i]



print((min(k-counter,a[n-1]-a[0])))
k,n=list(map(int,input().split()))

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

a.append(a[0]+k)

cnt=0



for i in range(n):

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

print((k-cnt))
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(a[0] + k - a[n - 1])
counter = 0
for i in range(n):
    if counter < a[i + 1] - a[i]:
        counter = a[i + 1] - a[i]
print((min(k - counter, a[n - 1] - a[0])))

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

-a.append(a[0] + k - a[n - 1]) -counter = 0 +a.append(a[0] + k) +cnt = 0 -    if counter < a[i + 1] - a[i]: -        counter = a[i + 1] - a[i] -print((min(k - counter, a[n - 1] - a[0]))) +    cnt = max(cnt, a[i + 1] - a[i]) +print((k - cnt))