#include <bits/stdc++.h>
using namespace std;
const int maxn = 100003;
int n, m;
long long read[maxn];
long long track[maxn];
long long debug = 0;
bool go(long long x) {
  int i, j;
  long long curpos = 1;
  for (i = 0, j = 0; i < n; i++) {
    if (abs(read[i] - track[j]) > x) continue;
    if (read[i] == track[j]) j++;
    if (read[i] > track[j]) {
      long long r1 = read[i] + x - 2 * (read[i] - track[j]);
      long long r2 = read[i] + (x - (read[i] - track[j])) / 2;
      curpos = max(r1, r2);
    } else
      curpos = read[i] + x;
    while (track[j] <= curpos && j < m) j++;
  }
  return j >= m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &read[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &track[i]);
  long long lp = 0, rp = 1000000000003LL;
  while (lp + 1LL < rp) {
    long long mid = (lp + rp - 1LL) / 2LL;
    if (go(mid))
      rp = mid + 1LL;
    else
      lp = mid + 1LL;
  }
  printf("%I64d\n", lp);
}
