#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long a[MAXN], b[MAXN], m, n;
bool check(long long num) {
  long long i, j;
  for (i = j = 1; i <= n; i++) {
    long long k = max(0ll, a[i] - b[j]);
    if (k > num) break;
    while (j <= m and
           2 * min(k, max(b[j] - a[i], 0ll)) + max(b[j] - a[i], k) <= num)
      j++;
  }
  return j > m;
}
int main() {
  long long i, j, k;
  scanf("%lld%lld", &n, &m);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (i = 1; i <= m; i++) scanf("%lld", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  long long l = 0, r = 999999999999999, o = 50, ans = 999999999999999;
  while (o--) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
}
