#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100005], a[100005];
int is(long long tm) {
  int p = 1;
  for (int i = 1; i <= n; i++) {
    if (a[p] <= h[i]) {
      long long dis = h[i] - a[p];
      if (dis > tm) return 0;
      long long r = max((tm - dis) / 2, tm - 2 * dis);
      while (a[p] - h[i] <= r && p <= m) p++;
    } else {
      while (a[p] - h[i] <= tm && p <= m) p++;
    }
    if (p > m) return 1;
  }
  return p > m;
}
int main() {
  while (~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", &a[i]);
    sort(h + 1, h + n + 1);
    sort(a + 1, a + m + 1);
    long long l = 0, r = 20000000000ll, mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (is(mid))
        r = mid - 1;
      else
        l = mid + 1;
    }
    printf("%I64d\n", l);
  }
  return 0;
}
