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

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



d = [None] * n

sum = 0

for i in range(n):

    if i == n-1:

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

    else:

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

    sum += d[i]

ans = 2 * 10**11

for i in range(n):

    if sum - d[i] < ans:

        ans = sum - d[i]

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

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



d = [None] * n

sum = 0

for i in range(n):

    if i == n-1:

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

    else:

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

    sum += d[i]

print((sum - max(d)))
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
d = [None] * n
sum = 0
for i in range(n):
    if i == n - 1:
        d[n - 1] = k - a[n - 1] + a[0]
    else:
        d[i] = a[i + 1] - a[i]
    sum += d[i]
ans = 2 * 10**11
for i in range(n):
    if sum - d[i] < ans:
        ans = sum - d[i]
print(ans)

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

-ans = 2 * 10**11 -for i in range(n): -    if sum - d[i] < ans: -        ans = sum - d[i] -print(ans) +print((sum - max(d)))