#include <bits/stdc++.h>
using namespace std;
long long A[100000], B[100000], ans = 0;
int m, n;
bool f(long long t) {
  int last = 0, current;
  long long a, b;
  for (int i = 0; i < n; i++) {
    for (current = last; current < m; current++) {
      a = abs(B[current] - A[i]);
      b = abs(B[last] - A[i]);
      a = min(a, b);
      b = B[current] - B[last];
      if (a + b > t) break;
    }
    last = current;
  }
  return last == m;
}
int main() {
  scanf("%d %d", &n, &m);
  long long u = 0, v = LLONG_MAX, mid;
  for (int i = 0; i < n; i++) scanf("%I64d", &A[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &B[i]);
  for (; u < v;) {
    mid = u + (v - u) / 2;
    if (f(mid))
      v = mid;
    else
      u = mid + 1;
  }
  printf("%I64d\n", u);
  return 0;
}
