import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); TreeSet set = new TreeSet<>(); for (int i = 0; i < n; i++) { set.add(Long.parseLong(sa[i])); } sa = br.readLine().split(" "); long[] b = new long[m]; for (int i = 0; i < m; i++) { b[i] = Long.parseLong(sa[i]); } br.close(); long inf = 2000000007; set.add(-inf); set.add(inf); long[] dp1 = new long[m]; long[] dp2 = new long[m]; for (int i = 0; i < m; i++) { long v1 = b[i] - set.floor(b[i]); if (i > 0) { dp1[i] = dp1[i - 1]; v1 = Math.min(v1, b[i] - b[i - 1]); } dp1[i] += v1; dp2[i] += set.ceiling(b[i]) - b[i]; if (i > 0) { dp2[i] += dp1[i - 1]; if (set.ceiling(b[i - 1]) == set.ceiling(b[i])) { dp2[i] = Math.min(dp2[i], dp2[i - 1]); } } } System.out.println(Math.min(dp1[m - 1], dp2[m - 1])); } }