import sys #input = sys.stdin.readline #文字列につけてはダメ input = sys.stdin.buffer.readline #文字列につけてはダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy def main(): N,M = map(int,input().split()); INF = pow(10,18) A = [-INF] + list(map(int,input().split())) + [INF] B = list(map(int,input().split())) ans = 0 j = 0 for i in range(N+1): if j >= M: break temp = [] left,right = A[i:i+2] while j < M and B[j] < right: temp.append(B[j]) j += 1 #print(temp,left,right) L = [0]; R = [0] for k in range(len(temp)): L.append(temp[k] - left) R.append(right - temp[-1-k]) R.reverse() #print(L,R) mn = INF for p,q in zip(L,R): mn = min(mn, p+q) ans += mn print(ans) if __name__ == '__main__': main()