#include <bits/stdc++.h>
using namespace std;
const long long MX = (1 << 20);
long long inf = (1ll << 62);
set<long long> S;
long long n, m;
long long pos[MX];
bool check(long long rad) {
  for (long long j = 1; j <= n; j++) {
    if (S.empty()) break;
    long long P = pos[j];
    long long mn = *S.begin();
    if (mn >= P) {
      while (!S.empty() && *S.begin() <= P + rad) S.erase(S.begin());
      continue;
    }
    long long fakss = P - mn;
    if (fakss > rad) return 0;
    long long rr = (rad - (P - mn)) / 2;
    auto it = S.upper_bound(P + rr);
    long long c1;
    if (it == S.end())
      c1 = inf;
    else
      c1 = *it;
    rr = rad - ((P - mn) * 2);
    it = S.upper_bound(P + rr);
    long long c2;
    if (it == S.end())
      c2 = inf;
    else
      c2 = *it;
    if (c1 < c2) swap(c1, c2);
    while (!S.empty() && *S.begin() < c1) S.erase(S.begin());
  }
  return S.empty();
}
int main() {
  scanf("%lld %lld", &n, &m);
  for (long long j = 1; j <= n; j++) scanf("%lld", &pos[j]);
  vector<long long> vec;
  for (long long j = 1; j <= m; j++) {
    long long x;
    scanf("%lld", &x);
    vec.push_back(x);
  }
  long long st = 0, en = 2e11, mid, best;
  while (st <= en) {
    mid = (st + en) / 2;
    S.clear();
    for (auto pp : vec) S.insert(pp);
    if (check(mid)) {
      en = mid - 1;
      best = mid;
    } else
      st = mid + 1;
  }
  cout << best << endl;
}
