#include <bits/stdc++.h>
using namespace std;
template <class T>
T cross(complex<T> a, complex<T> b) {
  return imag(a * conj(b));
}
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void setmax(T &a, T b) {
  if (b > a) a = b;
}
int N, M;
vector<long long> H;
vector<long long> P;
bool isGood(long long t) {
  vector<long long>::iterator np = P.begin();
  for (__typeof(H.begin()) nh = H.begin(); nh != H.end(); nh++) {
    long long beg = *np;
    long long cur = *nh;
    if (beg > cur) beg = cur;
    while (np != P.end()) {
      long long end = *np;
      if (end < cur) end = cur;
      long long dist = (end - cur) + (cur - beg) + min(end - cur, cur - beg);
      if (dist <= t) {
        np++;
      } else {
        break;
      }
    }
    if (np == P.end()) return true;
  }
  return false;
}
long long bSearch() {
  long long min = -1, max = 1ll << 40;
  while (max - min > 1) {
    long long mid = (max + min) / 2;
    if (isGood(mid))
      max = mid;
    else
      min = mid;
  }
  return max;
}
void io(istream &in, ostream &out) {
  in >> N >> M;
  H.resize(N);
  P.resize(M);
  for (int i = 0; i < N; i++) {
    in >> H[i];
  }
  for (int i = 0; i < M; i++) {
    in >> P[i];
  }
  cerr << "input read" << '\n';
  sort(H.begin(), H.end());
  sort(P.begin(), P.end());
  cerr << "sorted" << '\n';
  out << bSearch() << '\n';
}
int main() {
  ifstream fin("343C.in");
  if (fin.good()) {
    ofstream fout("343C.out");
    io(fin, fout);
    fin.close();
    fout.close();
  } else
    io(cin, cout);
  return 0;
}
