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

#K: 湖1周の長さ, N:湖の周りにある家の数



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



ans = 10**10

for i in range(N):

    for j in range(2):

        if j == 0: #時計周り

            if i == 0:

                dif = A[0]+(K-A[-1])

            else:

                dif = A[i] - A[i-1]

            ans = min(ans, K-dif)

        else: #半時計周り

            if i == N-1:

                dif = A[0]+(K-A[-1])

            else:

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

            ans = min(ans, K-dif)



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

#K: 湖1周の長さ, N:湖の周りにある家の数



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

A.sort()

dist = [A[0]+K-A[-1]] + [A[i]-A[i-1] for i in range(1, N)]

print((K-max(dist)))

K, N = list(map(int, input().split()))
# K: 湖1周の長さ, N:湖の周りにある家の数
A = list(map(int, input().split()))
ans = 10**10
for i in range(N):
    for j in range(2):
        if j == 0:  # 時計周り
            if i == 0:
                dif = A[0] + (K - A[-1])
            else:
                dif = A[i] - A[i - 1]
            ans = min(ans, K - dif)
        else:  # 半時計周り
            if i == N - 1:
                dif = A[0] + (K - A[-1])
            else:
                dif = A[i + 1] - A[i]
            ans = min(ans, K - dif)
print(ans)

K, N = list(map(int, input().split()))
# K: 湖1周の長さ, N:湖の周りにある家の数
A = list(map(int, input().split()))
A.sort()
dist = [A[0] + K - A[-1]] + [A[i] - A[i - 1] for i in range(1, N)]
print((K - max(dist)))

-ans = 10**10 -for i in range(N): -    for j in range(2): -        if j == 0:  # 時計周り -            if i == 0: -                dif = A[0] + (K - A[-1]) -            else: -                dif = A[i] - A[i - 1] -            ans = min(ans, K - dif) -        else:  # 半時計周り -            if i == N - 1: -                dif = A[0] + (K - A[-1]) -            else: -                dif = A[i + 1] - A[i] -            ans = min(ans, K - dif) -print(ans) +A.sort() +dist = [A[0] + K - A[-1]] + [A[i] - A[i - 1] for i in range(1, N)] +print((K - max(dist)))