from bisect import * def f(L): if L == []: return 0 n = len(L) ind = bisect_right(A, L[0]) pre = A[ind - 1] nex = A[ind] minv = min(nex - L[0], L[-1] - pre) for i in range(n - 1): val = L[i] - pre + nex - L[i + 1] minv = min(minv, val) return minv N, M = map(int, input().split()) inf = 10 ** 18 A = [-inf] + list(map(int, input().split())) + [inf] B = list(map(int, input().split())) D = [] for a in A: D.append((a, 1)) for b in B: D.append((b, 0)) D.sort() lst = [] ans = 0 for v, flag in D: if flag: ans += f(lst) lst = [] else: lst.append(v) print(ans)