#include <bits/stdc++.h>
using namespace std;
vector<long long> heads;
vector<long long> toRead;
inline bool ok(long long delta) {
  vector<long long> used(((int)heads.size()), 0);
  int headPtr = 0;
  long long lastPos = heads[0];
  int i = 0;
  while (i < ((int)toRead.size())) {
    long long pos = toRead[i];
    if (used[headPtr] + abs(lastPos - pos) > delta) {
      ++headPtr, lastPos = heads[headPtr];
      while (headPtr < ((int)heads.size()) and
             ((heads[headPtr] < pos - delta) or
              (used[headPtr] + abs(heads[headPtr] - pos) > delta))) {
        ++headPtr;
        lastPos = heads[headPtr];
      }
    }
    if (headPtr == ((int)heads.size())) return false;
    used[headPtr] += abs(lastPos - pos);
    ++i;
    while (i < ((int)toRead.size()) and
           toRead[i] <= heads[headPtr] + (delta - used[headPtr]) / 2)
      ++i;
    lastPos = pos;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    long long pos;
    cin >> pos;
    heads.push_back(pos);
  }
  sort(heads.begin(), heads.end());
  for (int i = 0; i < (m); ++i) {
    long long pos;
    cin >> pos;
    if (!binary_search(heads.begin(), heads.end(), pos)) toRead.push_back(pos);
  }
  sort(toRead.begin(), toRead.end());
  long long l = 0, r = (long long)2e18;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (!ok(mid))
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << "\n";
  return 0;
}
