import sys from heapq import heappush, heappop, heapify input = sys.stdin.buffer.readline N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) G = [[] for _ in range(N + M + 1)] S = [(x, 1) for x in A] + [(x, 0) for x in B] S.sort() for i, (x, c) in enumerate(S, 1): if c: G[0].append((i, 0)) G[i].append((0, 0)) for i in range(1, N + M): G[i].append((i + 1, S[i][0] - S[i - 1][0])) G[i + 1].append((i, S[i][0] - S[i - 1][0])) # https://tjkendev.github.io/procon-library/python/graph/min_st_prim.html used = [0] * (N + M + 1) que = [(c, w) for w, c in G[0]] used[0] = 1 heapify(que) ans = 0 while que: cv, v = heappop(que) if used[v]: continue used[v] = 1 ans += cv for w, c in G[v]: if used[w]: continue heappush(que, (c, w)) print(ans)