from collections import deque

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

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

A.appendleft(K - A[-1] + A[0])

sa_max = A[0]

for i in range(1, N):

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

    if sa_max < sa:

        sa_max = sa

print((A[-1] + A[0] - (sa_max + A[1])))

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

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

A.append(K - A[-1] + A[0])

sa_max = A[-1]

for i in range(N - 1):

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

    if sa_max < sa:

        sa_max = sa

print(((A[-2] - A[0]) + A[-1] - sa_max))

from collections import deque

K, N = list(map(int, input().split()))
A = deque(list(map(int, input().split())))
A.appendleft(K - A[-1] + A[0])
sa_max = A[0]
for i in range(1, N):
    sa = A[i + 1] - A[i]
    if sa_max < sa:
        sa_max = sa
print((A[-1] + A[0] - (sa_max + A[1])))

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(K - A[-1] + A[0])
sa_max = A[-1]
for i in range(N - 1):
    sa = A[i + 1] - A[i]
    if sa_max < sa:
        sa_max = sa
print(((A[-2] - A[0]) + A[-1] - sa_max))

-from collections import deque - -A = deque(list(map(int, input().split()))) -A.appendleft(K - A[-1] + A[0]) -sa_max = A[0] -for i in range(1, N): +A = list(map(int, input().split())) +A.append(K - A[-1] + A[0]) +sa_max = A[-1] +for i in range(N - 1): -print((A[-1] + A[0] - (sa_max + A[1]))) +print(((A[-2] - A[0]) + A[-1] - sa_max))