#include <bits/stdc++.h>
using namespace std;
struct node {
  int type;
  long long pos;
} a[200005];
int n, m;
long long L, R, M;
bool cmp(node A, node B) { return A.pos < B.pos; }
bool check(long long step) {
  int pre, pt, hd;
  long long dis;
  for (pt = 1; a[pt].type != 1; pt++)
    ;
  pre = (pt > 1) ? 1 : 0;
  while (true) {
    if (pre && a[pt].pos - a[pre].pos > step) return 0;
    if (!pre)
      dis = step;
    else
      dis = max(step - (a[pt].pos - a[pre].pos) * 2,
                (step - (a[pt].pos - a[pre].pos)) / 2);
    for (hd = pt + 1; hd <= n + m; hd++) {
      if (a[hd].type == 1) break;
      if (a[hd].pos - a[pt].pos > dis) break;
    }
    if (hd > n + m) return 1;
    if (a[hd].type == 1)
      pre = 0, pt = hd;
    else {
      pre = hd;
      for (pt = hd + 1; a[pt].type != 1 && pt <= n + m; pt++)
        ;
      if (pt > n + m) return 0;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    a[i].type = 1;
    scanf("%I64d", &a[i].pos);
  }
  for (int i = 1; i <= m; i++) {
    a[n + i].type = 2;
    scanf("%I64d", &a[n + i].pos);
  }
  sort(a + 1, a + n + m + 1, cmp);
  L = 0;
  R = 20000000000LL;
  while (L <= R) {
    M = (L + R) >> 1;
    if (check(M))
      R = M - 1;
    else
      L = M + 1;
  }
  printf("%I64d\n", L);
}
