#include <bits/stdc++.h>
using namespace std;
int n, m;
long long p[100010], h[100010];
bool ok(long long ans) {
  int now = 0;
  for (int i = 0; i < n; i++) {
    if (now == m) return true;
    if (p[now] < h[i] && abs(h[i] - p[now]) > ans) return false;
    long long L = p[now], maxR;
    if (L > h[i])
      maxR = h[i] + ans;
    else {
      maxR = max((L + ans + h[i]) / 2, ans - (h[i] - L) * 2 + h[i]);
    }
    while (p[now] <= maxR && now < m) now++;
  }
  return now == m;
}
int main() {
  long long MAXX = 1;
  for (int i = 1; i <= 10; i++) MAXX *= 10;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
  long long L = 0, R = MAXX * 2;
  while (L + 1 < R) {
    long long mid = (L + R) / 2;
    if (ok(mid))
      R = mid;
    else
      L = mid;
  }
  if (ok(L))
    printf("%I64d\n", L);
  else
    printf("%I64d\n", R);
  return 0;
}
