def main():
    lengths = list(map(int, input().split()))
    s = list(map(int, input().split()))
    t = list(map(int, input().split()))
    n, m = len(s), len(t)
    prevRow, nextRow = [99999999]*(m + 1), [99999999]*(m + 1)
    prevRow[0] = 0
    for i in range(n):
        for j in range(m):
            cost = abs(s[i] - t[j])
            nextRow[j+1] = cost + min(prevRow[j+1], nextRow[j], prevRow[j])
        prevRow[0] = 99999999
        nextRow,prevRow = prevRow,nextRow
    print(prevRow[m])

if __name__ == "__main__":
    main()
