#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:167772160")
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.);
long long H[100500], P[100500];
long long dp[100500];
long long LLABS(long long x) {
  if (x < 0) return -x;
  return x;
}
long long get(int x, int i, int p) {
  long long ans1 = LLABS(H[i] - P[x]) * 2 + LLABS(H[i] - P[p]);
  long long ans2 = LLABS(H[i] - P[x]) + LLABS(H[i] - P[p]) * 2;
  long long ans = min(ans1, ans2);
  if (x > 0) ans = max(dp[x - 1], ans);
  return ans;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf("%I64d", &H[i]);
  }
  for (int i = 0; i < M; ++i) {
    scanf("%I64d", &P[i]);
  }
  int frm = 0;
  int to = 0;
  memset(dp, 0x3f, sizeof(dp));
  int prvto = 0;
  for (int i = 0; i < N; ++i) {
    if (i > 0) {
      while (frm < M && P[frm] <= H[i - 1]) ++frm;
    }
    if (i + 1 == N) {
      to = M;
    } else {
      while (to < M && P[to] < H[i + 1]) ++to;
    }
    int x = prvto;
    for (int p = to - 1; p >= frm; --p) {
      if (P[p] <= H[i]) {
        break;
      } else {
        long long cur = P[p] - H[i];
        if (P[prvto] < H[i]) cur = max(cur, dp[prvto]);
        dp[p] = min(dp[p], cur);
        while (x > 0 && get(x - 1, i, p) <= get(x, i, p)) --x;
        dp[p] = min(dp[p], get(x, i, p));
      }
    }
    for (int p = frm; p < to; ++p) {
      if (P[p] <= H[i]) {
        long long cur = H[i] - P[p];
        if (p > 0) cur = max(cur, dp[p - 1]);
        dp[p] = min(dp[p], cur);
      } else {
        break;
      }
    }
    prvto = max(0, to - 1);
  }
  cout << dp[M - 1] << endl;
  return 0;
}
