f=lambda:[*list(map(int,input().split()))]

k,n=f()

l=f()

l+=[l[0]+k]

a=0

for i in range(n):

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

print((k-a))
k,n,*l=list(map(int,open(0).read().split()))

l+=[l[0]+k]

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

k, n, *l = list(map(int, open(0).read().split()))
l += [l[0] + k]
print((k - max(l[i + 1] - l[i] for i in range(n))))

-f = lambda: [*list(map(int, input().split()))] -k, n = f() -l = f() +k, n, *l = list(map(int, open(0).read().split())) -a = 0 -for i in range(n): -    a = max(a, l[i + 1] - l[i]) -print((k - a)) +print((k - max(l[i + 1] - l[i] for i in range(n))))