p,q= input().split()

a,b =(int(p), int(q))

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

f_list = list(f)

out_dis =f_list[0] + a -f_list[b-1]

dis_list=[out_dis]

for i in range(b-1):

    dis = f_list[i+1]-f_list[i]

    dis_list.append(dis)



print((int((sum(dis_list)-max(dis_list)))))
k , n= list(map(int, input().split()))

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

diff_list = []

for i in range(n-1):

    diff_list.append(a_list[i+1]- a_list[i])

diff_list.append(k-a_list[n-1] + a_list[0])

print((sum(diff_list)-max(diff_list)))
p, q = input().split()
a, b = (int(p), int(q))
f = list(map(int, input().split()))
f_list = list(f)
out_dis = f_list[0] + a - f_list[b - 1]
dis_list = [out_dis]
for i in range(b - 1):
    dis = f_list[i + 1] - f_list[i]
    dis_list.append(dis)
print((int((sum(dis_list) - max(dis_list)))))

k, n = list(map(int, input().split()))
a_list = list(map(int, input().split()))
diff_list = []
for i in range(n - 1):
    diff_list.append(a_list[i + 1] - a_list[i])
diff_list.append(k - a_list[n - 1] + a_list[0])
print((sum(diff_list) - max(diff_list)))

-p, q = input().split() -a, b = (int(p), int(q)) -f = list(map(int, input().split())) -f_list = list(f) -out_dis = f_list[0] + a - f_list[b - 1] -dis_list = [out_dis] -for i in range(b - 1): -    dis = f_list[i + 1] - f_list[i] -    dis_list.append(dis) -print((int((sum(dis_list) - max(dis_list))))) +k, n = list(map(int, input().split())) +a_list = list(map(int, input().split())) +diff_list = [] +for i in range(n - 1): +    diff_list.append(a_list[i + 1] - a_list[i]) +diff_list.append(k - a_list[n - 1] + a_list[0]) +print((sum(diff_list) - max(diff_list)))