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

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

li = []

for i in range(n-1):

    li.append(L[i+1]-L[i])

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

#print(L,li)



min1 =10**10

#min1 = k-L[n-1]+L[0]

for i in range(n):

   min1 = min(min1,(k-li[i]))

   #print(min1)

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

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



li = []

for i in range(n-1):

    li.append(L[i+1]-L[i])

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

li.sort()

print((k-li[n-1]))
k, n = list(map(int, input().split()))
L = list(map(int, input().split()))
li = []
for i in range(n - 1):
    li.append(L[i + 1] - L[i])
li.append(k - L[n - 1] + L[0])
# print(L,li)
min1 = 10**10
# min1 = k-L[n-1]+L[0]
for i in range(n):
    min1 = min(min1, (k - li[i]))
    # print(min1)
print(min1)

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

-# print(L,li) -min1 = 10**10 -# min1 = k-L[n-1]+L[0] -for i in range(n): -    min1 = min(min1, (k - li[i])) -    # print(min1) -print(min1) +li.sort() +print((k - li[n - 1]))