#include <bits/stdc++.h>
const int maxn = 2e5 + 3;
int n, m;
long long h[maxn], b[maxn];
bool check(const long long &t) {
  int cur = 0;
  for (int i = 0; i < n; ++i) {
    long long head = h[i];
    long long left = b[cur];
    if (head - left > t) return false;
    long long right;
    if (left >= head)
      right = head + t;
    else
      right = std::max(head, std::max(t - (head - left) * 2ll + head,
                                      head + (t - (head - left)) / 2ll));
    cur = std::upper_bound(b + cur, b + m, right) - b;
    if (cur >= m) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", h + i);
  for (int j = 0; j < m; ++j) scanf("%lld", b + j);
  long long r = 4e10 + 3, l = -1;
  while (r - l > 1) {
    long long mid = (l + r) / 2ll;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%lld\n", r);
  return 0;
}
