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

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



b = [0] * (k-1)

for i in range(k-1):

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

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



print((sum(b)-max(b)))
n, k = list(map(int,input().split()))

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

b = [a[i+1]-a[i] for i in range(k-1)]

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

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

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

-b = [0] * (k - 1) -for i in range(k - 1): -    b[i] = a[i + 1] - a[i] +b = [a[i + 1] - a[i] for i in range(k - 1)] -print((sum(b) - max(b))) +print((n - max(b)))