K, N = [int(_) for _ in input().split()]

A = [int(_) for _ in input().split()]

A.sort()

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

print((K - max(A_diff)))

K, N = [int(_) for _ in input().split()]

# X = int(input())

A = [int(_) for _ in input().split()]

A.sort()

diff = [A[i+1] - A[i] for i in range(N-1)]

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

print((K-max(diff)))

K, N = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A.sort()
A_diff = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] + K - A[-1]]
print((K - max(A_diff)))

K, N = [int(_) for _ in input().split()]
# X = int(input())
A = [int(_) for _ in input().split()]
A.sort()
diff = [A[i + 1] - A[i] for i in range(N - 1)]
diff.append(A[0] + K - A[-1])
print((K - max(diff)))

+# X = int(input()) -A_diff = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] + K - A[-1]] -print((K - max(A_diff))) +diff = [A[i + 1] - A[i] for i in range(N - 1)] +diff.append(A[0] + K - A[-1]) +print((K - max(diff)))