#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
long long h[N], p[N], n, m, i, l, r, mid, j, f;
int isok(long long d) {
  j = 0;
  f = 0;
  for (i = 0; i < n; i++) {
    if (abs(h[i] - p[j]) > d) continue;
    if (h[i] == p[j]) j++;
    if (h[i] > p[j])
      f = max(p[j] + d - (h[i] - p[j]), h[i] + (d - (h[i] - p[j])) / 2);
    else
      f = d + h[i];
    while (j < m && p[j] <= f) j++;
  }
  if (j < m)
    return 0;
  else
    return 1;
}
int main() {
  scanf("%I64d", &n);
  scanf("%I64d", &m);
  for (i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (i = 0; i < m; i++) scanf("%I64d", &p[i]);
  l = -1;
  r = abs(h[0] - p[0]) * 2 + abs(h[0] - p[m - 1]);
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (isok(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%I64d\n", r);
  return 0;
}
