#!/usr/bin/env python3
import sys
import bisect   

def solve(N: int, M: int, H: "List[int]", W: "List[int]"):
    H =sorted(H)
    rH =sorted(H,reverse=True)

    com_h =[0] * ((N-1)//2+2)
    com_rh =[0] * ((N-1)//2+2)

    com_h[1] = H[1] - H[0]
    com_rh[1] = rH[0] - rH[1]
    
    for i in range(1,(N-1)//2):
        com_h[i+1] = com_h[i] + (H[i*2+1]-H[i*2])
        com_rh[i+1] = com_rh[i] + (rH[i*2]- rH[i*2+1])


    def ins_h(wi, ind):
        if ind % 2 == 0:
            l = com_h[ind//2]
            r = com_rh[(N-ind)//2]
            bt = H[ind]-wi
        elif 0 < ind:
            l = com_h[(ind-1)//2]
            r = com_rh[(N-(ind-1))//2]
            bt = wi-H[ind-1]
        else:
            return 10**6
        return l+r+bt
    
    def insr_h(wi, ind):
        if ind % 2 == 0:
            l = com_h[ind//2]
            r = com_rh[(N-ind)//2]
            bt = wi-H[ind]
        elif ind < N-1:
            l = com_h[(ind-1)//2]
            r = com_rh[((N-(ind-1))//2)]
            bt = H[ind+1]-wi
        else:
            return 10**6
        return l+r+bt

    # print(com_h)
    # print(com_rh)
    min_ = 10**6
    for wi in W:
        bl = bisect.bisect_left(H, wi)
        br = bisect.bisect_right(H, wi)
        sl = ins_h(wi,bl)
        sr = insr_h(wi,br)
        # sr = 1111111110
        print(wi, sl, sr)
        min_ = min(min_,min(sl,sr))

    print(min_)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    W = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, H, W)

if __name__ == '__main__':
    main()
