#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int res = 0;
  int neg;
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9' || ch == '-') {
      if (ch == '-')
        neg = -1;
      else
        neg = 1, res = ch - '0';
      break;
    }
  }
  while (true) {
    char ch = getchar();
    if (ch >= '0' && ch <= '9')
      res *= 10, res += ch - '0';
    else
      break;
  }
  return res * neg;
}
const int maxn = 100020;
const int maxm = 1020;
const int MOd = 1e7;
int a, b;
long long h[maxn], p[maxn];
bool f(long long n) {
  int j = 1;
  for (int i = 1; i <= a; i++) {
    if (h[i] <= p[j]) {
      while (j <= b && p[j] <= h[i] + n) j++;
      if (j > b) return true;
    } else {
      int y = j;
      j--;
      for (int k = 17; k >= 0; k--) {
        if (j + (1 << k) > b) continue;
        long long r = max(p[j + (1 << k)], h[i]);
        if (min(r - h[i], h[i] - p[y]) + r - p[y] <= n) j += (1 << k);
      }
      j++;
      if (j > b) return true;
    }
  }
  return j > b;
}
int main() {
  scanf("%d %d", &a, &b);
  for (int i = 1; i <= a; i++) scanf("%lld", &h[i]);
  for (int i = 1; i <= b; i++) scanf("%lld", &p[i]);
  sort(h + 1, h + a + 1);
  sort(p + 1, p + b + 1);
  long long t = -1;
  for (int k = 40; k >= 0; k--)
    if (!f(t + (1ll << k))) t += (1ll << k);
  t++;
  printf("%lld\n", t);
  return 0;
}
