import std; void main() { int N, M; readf("%d %d\n", N, M); auto A = readln.chomp.split.to!(long[]); auto B = readln.chomp.split.to!(long[]); long res; int i, j; while (j < M) { if (A[i] > B[j]) { if (i == N - 1 && j == M - 1) { break; } res += A[i] - B[j]; while (j < M - 1 && A[i] > B[j]) { ++j; } } else { while (i < N - 1 && A[i+1] < B[j]) { ++i; } long op = abs(B[j] - A[i]); if (i < N - 1 && op > A[i+1] - B[j]) { res += A[i+1] - B[j]; ++i; } else { res += op; A[i] = B[j]; } ++j; } } res.writeln; }