#include <bits/stdc++.h>
using namespace std;
const long long maxN = 2e6 + 5;
const long long inf = 1e10;
const long long mod = 1e9 + 7;
long long n, m;
long long h[maxN], p[maxN];
bool can_visit(long long s, long long a, long long b, long long t) {
  if (a > s) a = s;
  if (b < s) b = s;
  long long x = s - a;
  long long y = b - s;
  long long z = min(2 * x + y, 2 * y + x);
  return z <= t;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> h[i];
  for (long long i = 1; i <= m; i++) cin >> p[i];
  long long l = 0;
  long long r = (long long)1e11;
  long long mid = (l + r) >> 1;
  while (l < r) {
    mid = (l + r) >> 1;
    long long last = 1;
    for (long long i = 1; i <= n; i++) {
      long long low = last;
      long long high = m + 1;
      long long center = (low + high + 1) >> 1;
      while (low < high) {
        center = (low + high + 1) >> 1;
        if (can_visit(h[i], p[last], p[center - 1], mid))
          low = center;
        else
          high = center - 1;
      }
      last = low;
    }
    if (last == m + 1)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
