#include <bits/stdc++.h>
using namespace std;
int n, m;
const int mxn = (1e5) + 5;
long long h[mxn];
long long p[mxn];
bool check(long long x) {
  int it = 1;
  for (int i = 1; i <= n; ++i) {
    if (it > m) break;
    long long vl = 0;
    if (p[it] <= h[i]) {
      vl = h[i] - p[it];
      if (vl > x) return false;
      while (it <= m && p[it] <= h[i]) ++it;
    }
    while (it <= m && 2 * vl + (p[it] - h[i]) <= x) ++it;
    while (it <= m && (p[it] - h[i]) * 2 + vl <= x) ++it;
  }
  if (it > m) return true;
  return false;
}
void bs() {
  long long l = 0;
  long long r = (1LL << 60);
  long long ans = -1;
  while (l <= r) {
    long long md = (l + r) / 2;
    if (check(md)) {
      ans = md;
      r = md - 1;
    } else
      l = md + 1;
  }
  printf("%I64d\n", ans);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%I64d", &h[i]);
  for (int i = 1; i <= m; ++i) scanf("%I64d", &p[i]);
  bs();
  return 0;
}
