#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100010], b[100010];
bool pd(long long a, long long l, long long r, long long t) {
  if (a < l) {
    if (r - a <= t)
      return true;
    else
      return false;
  } else if (a > r) {
    if (a - l <= t)
      return true;
    else
      return false;
  } else {
    if (r - l + min(a - l, r - a) <= t)
      return true;
    else
      return false;
  }
}
bool can(long long x) {
  int j = 0;
  for (int i = 0; i < n; i++) {
    int k = j;
    while (k < m && pd(a[i], b[j], b[k], x)) k++;
    if (k == m) return true;
    j = k;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%I64d", &b[i]);
  }
  long long l = 0;
  long long r = 1000000000000ll;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
