N,M = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) A = [[A[i], True] for i in range(N)] B = [[B[i], False] for i in range(M)] AB = sorted(A + B, key = lambda x:x[0]) G = [[] for i in range(N + M)] import heapq as hq q = [] for i in range(N + M - 1): G[i].append([i + 1, AB[i + 1][0] - AB[i][0]]) G[i + 1].append([i, AB[i + 1][0] - AB[i][0]]) if AB[i][1]: hq.heappush(q, (0, i)) if AB[N + M - 1][1]: hq.heappush(q, (0, N + M - 1)) ans = 0 seen = set() while q: d, v = hq.heappop(q) if v in seen: continue seen.add(v) ans += d for child, cost in G[v]: if child in seen: continue hq.heappush(q, (cost, child)) print(ans)