K, N = list(map(int, input().split()))

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

li = []

for i in range(N):

    if i == 1:

        cadA = A[N-1] - A[0]

    else:

        cadA = K - A[i] + A[i-1]

    if i == N-1:

        cadB = A[N-1] - A[0]

        cadB = 100000000000

    else:

        cadB = A[i] + (K - A[i+1])

        cadB = 100000000000

    li.append(min(cadA, cadB))

print((min(li)))
K, N = list(map(int, input().split()))

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

distance = [0] * N

for i in range(N):

    if not i == N-1:

        distance[i] =  A[i+1] - A[i]

    else:

        distance[N-1] = A[0] + (K - A[N-1])

distance.sort()

distance.pop()

print((sum(distance)))

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
li = []
for i in range(N):
    if i == 1:
        cadA = A[N - 1] - A[0]
    else:
        cadA = K - A[i] + A[i - 1]
    if i == N - 1:
        cadB = A[N - 1] - A[0]
        cadB = 100000000000
    else:
        cadB = A[i] + (K - A[i + 1])
        cadB = 100000000000
    li.append(min(cadA, cadB))
print((min(li)))

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
distance = [0] * N
for i in range(N):
    if not i == N - 1:
        distance[i] = A[i + 1] - A[i]
    else:
        distance[N - 1] = A[0] + (K - A[N - 1])
distance.sort()
distance.pop()
print((sum(distance)))

-li = [] +distance = [0] * N -    if i == 1: -        cadA = A[N - 1] - A[0] +    if not i == N - 1: +        distance[i] = A[i + 1] - A[i] -        cadA = K - A[i] + A[i - 1] -    if i == N - 1: -        cadB = A[N - 1] - A[0] -        cadB = 100000000000 -    else: -        cadB = A[i] + (K - A[i + 1]) -        cadB = 100000000000 -    li.append(min(cadA, cadB)) -print((min(li))) +        distance[N - 1] = A[0] + (K - A[N - 1]) +distance.sort() +distance.pop() +print((sum(distance)))