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

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

a.append(a[0]+k)

longd=0

for i in range(n):

    tmp=abs(a[i+1]-a[i])

    longd=max(longd,tmp)

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

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

a.append(a[0]+k)



x=0

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

    dis=abs(a[i+1]-a[i])

    x=max(x,dis)



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

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

-longd = 0 -for i in range(n): -    tmp = abs(a[i + 1] - a[i]) -    longd = max(longd, tmp) -print((k - longd)) +x = 0 +for i in range(len(a) - 1): +    dis = abs(a[i + 1] - a[i]) +    x = max(x, dis) +print((k - x))