#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  for (auto &hi : h) cin >> hi;
  vector<long long> p(m);
  for (auto &pi : p) cin >> pi;
  auto calc = [&](long long head, int s, int t) {
    return min(abs(head - p[s]), abs(head - p[t])) + (p[t] - p[s]);
  };
  auto check = [&](long long k) {
    int prv = 0;
    for (auto head : h) {
      int cur = prv;
      while (cur < m && calc(head, prv, cur) <= k) cur++;
      if (cur == m) return true;
      prv = cur;
    }
    return false;
  };
  auto binary_search = [&](long long ok, long long ng) {
    assert(check(ok) == true);
    assert(check(ng) == false);
    while (abs(ng - ok) > 1) {
      long long mid = (ng + ok) / 2;
      (check(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  cout << binary_search(INF, -1) << endl;
  return 0;
}
