import numpy as np

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

A = np.array([int(i) for i in input().split()])

B = A[1:]

B = np.insert(B, N - 1, A[0] + K)

X = B - A

print((sum(X) - max(X)))
import numpy as np

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

A = np.array([int(i) for i in input().split()])

B = A[1:]

B = np.insert(B, N - 1, A[0] + K)

X = B - A

print((K - max(X)))

import numpy as np

K, N = list(map(int, input().split()))
A = np.array([int(i) for i in input().split()])
B = A[1:]
B = np.insert(B, N - 1, A[0] + K)
X = B - A
print((sum(X) - max(X)))

import numpy as np

K, N = list(map(int, input().split()))
A = np.array([int(i) for i in input().split()])
B = A[1:]
B = np.insert(B, N - 1, A[0] + K)
X = B - A
print((K - max(X)))

-print((sum(X) - max(X))) +print((K - max(X)))