import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Field[] fields = new Field[n + m]; for (int i = 0; i < n; i++) { fields[i] = new Field(true, sc.nextInt()); } for (int i = n; i < n + m; i++) { fields[i] = new Field(false, sc.nextInt()); } Arrays.sort(fields); UnionFindTree uft = new UnionFindTree(n + m + 1); ArrayList list = new ArrayList<>(); for (int i = 0; i < n + m - 1; i++) { if (fields[i].isRed) { uft.unite(i, n + m); } list.add(new Path(i, i + 1, fields[i + 1].value - fields[i].value)); } if (fields[n + m - 1].isRed) { uft.unite(n + m - 1, n + m); } Collections.sort(list); long ans = 0; for (Path p : list) { if (!uft.same(p)) { uft.unite(p); ans += p.value; } } System.out.println(ans); } static class Field implements Comparable { boolean isRed; int value; public Field(boolean isRed, int value) { this.isRed = isRed; this.value = value; } public int compareTo(Field another) { return value - another.value; } } static class Path implements Comparable { int left; int right; int value; public Path(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Path another) { return value - another.value; } } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Path p) { return same(p.left, p.right); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Path p) { unite(p.left, p.right); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }