#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b > a) return gcd(b, a);
  return (b == 0) ? a : gcd(b, a % b);
}
int bitcount(int a) { return (a != 0) ? bitcount(a & (a - 1)) + 1 : 0; }
long long h[100005], p[100005], m, n;
long long bs1(long long val, long long pos, long long head) {
  long long hi, lo, mid, v1, v2, v;
  hi = m - 1, lo = pos;
  while (hi >= lo) {
    mid = (hi + lo) / 2;
    v1 = p[mid] - p[pos] + abs(p[mid] - h[head]);
    v2 = p[mid] - p[pos] + abs(p[pos] - h[head]);
    v = min(v1, v2);
    if (v <= val)
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  return lo;
}
long long bs() {
  long long hi, lo, mid, cur, i;
  hi = 20000000000, lo = 0;
  while (hi >= lo) {
    mid = (hi + lo) / 2;
    cur = 0;
    bool fail = 0;
    for (i = 0; i < n; i++) {
      if (cur >= m) continue;
      if (p[cur] < h[i]) {
        if (abs(p[cur] - h[i]) > mid) {
          fail = 1;
          break;
        }
      }
      cur = bs1(mid, cur, i);
    }
    if (cur < m) fail = 1;
    if (fail)
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  return lo;
}
int main() {
  long long i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> h[i];
  for (i = 0; i < m; i++) cin >> p[i];
  cout << bs() << endl;
  return 0;
}
