#include <bits/stdc++.h>
#pragma warning(disable : 4786)
using namespace std;
long long heads[100005], tracks[100005];
int n, m;
long long Abs(long long x) { return x < 0 ? -x : x; }
int check(long long x) {
  int i, j = 0;
  for (i = 0; i < n; i++) {
    if (Abs(heads[i] - tracks[j]) > x) continue;
    int lo = j, hi = m - 1, k = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      long long t1 = Abs(heads[i] - tracks[mid]) + tracks[mid] - tracks[j];
      long long t2 = Abs(heads[i] - tracks[j]) + tracks[mid] - tracks[j];
      long long t = ((t1) < (t2) ? (t1) : (t2));
      if (t <= x)
        k = mid, lo = mid + 1;
      else
        hi = mid - 1;
    }
    if (k < 0) continue;
    j = k + 1;
    if (j == m) return 1;
  }
  return 0;
}
int main() {
  int i, j, k, T;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> heads[i];
  for (i = 0; i < m; i++) cin >> tracks[i];
  long long lo = 0, hi = 1;
  for (i = 0; i < 16; i++) hi *= (long long)10;
  long long ans = -1;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    if (check(mid))
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
