#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
long long a[N], b[N], n, m;
bool check(long long len) {
  long long i = 1, x = 1, y = 1;
  for (i = 1; i <= n && y <= m; i++) {
    while (min(abs(a[i] - b[x]), abs(a[i] - b[y])) + b[y] - b[x] <= len &&
           y <= m)
      y++;
    x = y;
  }
  return y > m;
}
long long bs(long long L, long long R) {
  while (L < R) {
    if (check((L + R >> 1)))
      R = (L + R >> 1);
    else
      L = (L + R >> 1) + 1;
  }
  return L;
}
int main() {
  int i, j, k, T;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= m; i++) cin >> b[i];
  cout << bs(0, 1e11) << endl;
  return 0;
}
