

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

A_list = [int(s) for s in input().split()]



d_list = []

for i, A in enumerate(A_list):

    if i == N - 1:

        d = K - A_list[i] + A_list[0]

    else:

        d = A_list[i + 1] - A_list[i]

    d_list.append(d)



d_sum_min = K - max(d_list)

print(d_sum_min)

k, n = [int(x) for x in input().split()]



a_list = [int(x) for x in input().split()]

a_list.append(k + a_list[0])



d_list = [a_list[i + 1] - a_list[i] for i in range(n)]

print((k - max(d_list)))
K, N = [int(s) for s in input().split()]
A_list = [int(s) for s in input().split()]
d_list = []
for i, A in enumerate(A_list):
    if i == N - 1:
        d = K - A_list[i] + A_list[0]
    else:
        d = A_list[i + 1] - A_list[i]
    d_list.append(d)
d_sum_min = K - max(d_list)
print(d_sum_min)

k, n = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
a_list.append(k + a_list[0])
d_list = [a_list[i + 1] - a_list[i] for i in range(n)]
print((k - max(d_list)))

-K, N = [int(s) for s in input().split()] -A_list = [int(s) for s in input().split()] -d_list = [] -for i, A in enumerate(A_list): -    if i == N - 1: -        d = K - A_list[i] + A_list[0] -    else: -        d = A_list[i + 1] - A_list[i] -    d_list.append(d) -d_sum_min = K - max(d_list) -print(d_sum_min) +k, n = [int(x) for x in input().split()] +a_list = [int(x) for x in input().split()] +a_list.append(k + a_list[0]) +d_list = [a_list[i + 1] - a_list[i] for i in range(n)] +print((k - max(d_list)))