#include <bits/stdc++.h>
using namespace std;
struct zda {
  long long int w;
  int head;
};
bool por(zda a, zda b) { return ((a.w == b.w) ? a.head < b.head : a.w < b.w); }
vector<zda> wsio;
int n, m;
void dane() {
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    zda a;
    scanf("%I64d", &a.w);
    a.head = 1;
    wsio.push_back(a);
  }
  for (int i = (0); i < (m); i++) {
    zda a;
    scanf("%I64d", &a.w);
    a.head = 0;
    wsio.push_back(a);
  }
  sort(wsio.begin(), wsio.end(), por);
}
bool spr(long long int v) {
  long long int last = 0;
  int it = 0;
  bool ok = 1;
  while (it < wsio.size()) {
    if (wsio[it].head == 1) {
      long long int L = 0, P = 0;
      P = wsio[it].w - last;
      L = 2 * P;
      if (last == 0) L = P = 0;
      if (P > v) ok = 0;
      long long int akt = wsio[it].w;
      if (it + 1 != wsio.size())
        while (wsio[it + 1].head != 1 && it + 1 != wsio.size()) {
          if (L + wsio[it + 1].w - akt <= v ||
              P + (wsio[it + 1].w - akt) * 2 <= v)
            it++;
          else
            break;
        }
      last = 0;
    } else {
      if (last == 0) last = wsio[it].w;
    }
    it++;
  }
  if (ok && last == 0) return 1;
  return 0;
}
void licz() {
  long long int p = 0, k = 40000000000;
  while (p != k) {
    long long int s = (p + k) / 2;
    if (spr(s))
      k = s;
    else
      p = s + 1;
  }
  cout << p << "\n";
}
int main() {
  dane();
  licz();
  return 0;
}
