import heapq import bisect N,M = map(int, input().split()) A = [-10**12]+list(map(int, input().split()))+[10**12] B = list(map(int, input().split())) SB = set() d = [] for i in range(M): b = B[i] j = bisect.bisect(A,b) if A[j]-b>b-A[j-1]: heapq.heappush(d,(b-A[j-1],i)) else: heapq.heappush(d,(A[j]-b,i)) ans = 0 while len(d): v,i = heapq.heappop(d) if not i in SB: ans+=v SB.add(i) if i>0 and not i-1 in SB: heapq.heappush(d,(B[i]-B[i-1],i-1)) if i