#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int N, M;
long long A[MAXN], B[MAXN];
bool check(long long t) {
  register int i;
  int las = 0;
  for (i = 1; i <= N; ++i) {
    if (A[i] - B[las + 1] > t) return 0;
    long long far;
    if (B[las + 1] <= A[i])
      far = max(t - (A[i] - B[las + 1]) * 2, (t - (A[i] - B[las + 1])) / 2);
    else
      far = t;
    far += A[i];
    while (B[++las] <= far && las <= M)
      ;
    --las;
    if (las == M) return 1;
  }
  return las == M ? 1 : 0;
}
int main() {
  register int i;
  scanf("%d%d", &N, &M);
  for (i = 1; i <= N; ++i) scanf("%lld", A + i);
  for (i = 1; i <= M; ++i) scanf("%lld", B + i);
  long long l = 0, r = 100000000000ll;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", r);
  return 0;
}
