#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 332222;
struct HF {
  long long x;
  int t;
  HF(long long _x, int _t) {
    x = _x;
    t = _t;
  }
  HF() {}
};
int n, m, N;
long long h[MAX_N], p[MAX_N];
HF a[MAX_N], b[MAX_N];
int cmp(HF x, HF y) {
  if (x.x != y.x) return x.x < y.x;
  return x.t < y.t;
}
int cks(long long w) {
  long long cv = -1, pm = 10000000000000LL;
  for (int i = 1; i <= N; ++i) {
    HF v = b[i];
    if (v.t == 1) {
      if (v.x > cv) pm = min(v.x, pm);
    }
    if (v.t == 0) {
      if (pm != 10000000000000LL) {
        if (v.x - pm > w) return 0;
        long long tmp = w - max(2 * (v.x - pm), 0LL);
        tmp = max(tmp, (w - (v.x - pm)) / 2);
        pm = 10000000000000LL;
        cv = max(cv, v.x + max(tmp, 0LL));
      } else {
        cv = max(cv, v.x + w);
      }
    }
  }
  return pm == 10000000000000LL;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &h[i]);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%I64d", &p[i]);
  }
  for (int i = 1; i <= n; ++i) {
    a[++N] = HF(h[i], 0);
  }
  for (int i = 1; i <= m; ++i) {
    a[++N] = HF(p[i], 1);
  }
  sort(a + 1, a + 1 + N, cmp);
  int N2 = 1;
  b[1] = a[1];
  for (int i = 2; i <= N; ++i) {
    if (a[i].x != a[i - 1].x) b[++N2] = a[i];
  }
  N = N2;
  long long l = -1, r = 1000000000000000000LL;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (cks(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
}
