#include <bits/stdc++.h>
using namespace std;
vector<long long> poli, head;
long long n, m, pishte, zaman, t, l = -1, r = 2e12 + 5, t1, t2;
int main() {
  cin >> n >> m;
  while (n--) {
    cin >> pishte;
    head.push_back(pishte);
  }
  while (m--) {
    cin >> pishte;
    poli.push_back(pishte);
  }
  while (r - l > 1) {
    zaman = (r + l) / 2;
    auto ithead = head.begin();
    auto itpead = poli.begin();
    while (ithead < head.end()) {
      t = zaman;
      if (itpead == poli.end()) break;
      if (t < abs(*ithead - *itpead)) {
        ithead++;
        continue;
      }
      if (*ithead > *itpead) {
        t1 = t;
        t -= (*ithead - *itpead);
        t /= 2;
        if (t >= (*ithead - *itpead)) {
          t1 -= 2 * (*ithead - *itpead);
          itpead = upper_bound(poli.begin(), poli.end(), *ithead + t1);
        } else {
          itpead = upper_bound(poli.begin(), poli.end(), *ithead + t);
        }
      } else {
        itpead = upper_bound(poli.begin(), poli.end(), *ithead + t);
      }
      ithead++;
    }
    if (itpead == poli.end())
      r = zaman;
    else
      l = zaman;
  }
  cout << r;
}
