#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
const int N = 100100;
long long n, m;
long long h[N], p[N];
long long cost(long long i, long long s, long long e) {
  long long l = fabs(h[i] - p[s]);
  long long r = fabs(h[i] - p[e]);
  if (p[s] <= h[i] && h[i] <= p[e]) return l + r + min(l, r);
  return max(l, r);
}
bool solve(long long x) {
  int ptr = 0;
  for (int i = 0; i < n; i++) {
    int j = ptr;
    while (ptr < m && cost(i, j, ptr) <= x) ptr++;
  }
  return ptr == m;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> h[i];
  for (int i = 0; i < m; ++i) cin >> p[i];
  long long lo = 0, hi = 200000000000000LL, mid;
  long long resp = 0;
  while (lo < hi) {
    mid = (lo + hi) >> 1;
    if (solve(mid)) {
      resp = mid;
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << lo << endl;
  return 0;
}
