import numpy as np

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

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

b = np.zeros(n)

for i in range(0,n-1):

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

  

b[n-1] = k - a[n-1] + a[0]

ans = k - max(b)

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

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

b = [0 for i in range(n)]

for i in range(0,n-1):

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



b[n-1] = k - a[n-1] + a[0]

ans = k - max(b)

print((int(ans)))
import numpy as np

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

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

-import numpy as np - -b = np.zeros(n) +b = [0 for i in range(n)]