#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[101010], p[101010];
bool C(long long num) {
  int cnt = 0;
  long long left = -1;
  for (int i = 0; i < n; i++) {
    if (h[i] <= p[cnt]) {
      left = max(left, h[i] + num);
    } else if (num >= h[i] - p[cnt]) {
      long long canMove =
          max((num - (h[i] - p[cnt])) / 2, num - 2 * (h[i] - p[cnt]));
      left = h[i] + canMove;
    }
    while (cnt < m && p[cnt] <= left) cnt++;
    if (cnt == m) return true;
  }
  return false;
}
long long solve() {
  long long lb = 0, ub = 1e18;
  if (C(lb)) return lb;
  while (ub - lb > 1) {
    long long mid = (ub + lb) / 2;
    if (C(mid))
      ub = mid;
    else
      lb = mid;
  }
  return ub;
}
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 ans = solve();
  printf("%lld\n", ans);
  return 0;
}
