#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, m;
long long h[N], p[N];
bool vis[N];
bool can(long long mx) {
  for (int i = 0; i < n; ++i) vis[i] = false;
  int at = 0;
  while (at < m) {
    int k = lower_bound(h, h + n, p[at]) - h - 1;
    if (k >= 0 && !vis[k] && h[k] + mx >= p[at]) {
      vis[k] = true;
      at = upper_bound(p, p + m, h[k] + mx) - p;
    } else {
      if (++k >= n) break;
      if (h[k] - p[at] > mx) break;
      long long can =
          max(mx - ((h[k] - p[at]) << 1), (mx - (h[k] - p[at])) >> 1);
      if (can < 0) break;
      vis[k] = true;
      at = upper_bound(p, p + m, h[k] + can) - p;
    }
  }
  return at == m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", &h[i]);
  for (int i = 0; i < m; ++i) scanf("%lld", &p[i]);
  long long l = 0, r = 20000000010LL, res = -1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (can(mid)) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", res);
  return 0;
}
