#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
const long long inf = 1e11 + 100;
int n, m;
long long hi[maxn], pi[maxn];
bool check(long long k) {
  int o = 1;
  for (int i = 1; i <= n; i++) {
    long long p = k;
    if (hi[i] >= pi[o]) {
      if (k >= (hi[i] - pi[o])) {
        p = max((p - hi[i] + pi[o]) / 2, p - 2 * (hi[i] - pi[o]));
        if (p < 0) p = 0;
      } else
        return 0;
    }
    o = upper_bound(pi + 1, pi + m + 1, hi[i] + p) - pi;
    if (o > m) return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &hi[i]);
  for (int i = 1; i <= m; i++) scanf("%lld", &pi[i]);
  long long lb = 0, ub = inf, ans;
  while (lb <= ub) {
    long long mid = (lb + ub) / 2;
    if (check(mid))
      ans = mid, ub = mid - 1;
    else
      lb = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
