#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long h[100002], p[100002];
bool CanRead(long long tg) {
  long long lastReadInd = 1;
  long long lastpos = 0;
  for (long long i = 1; i <= n; i++) {
    if (h[i] <= p[lastReadInd]) {
      lastpos = h[i] + tg;
    } else if (h[i] - p[lastReadInd] <= tg) {
      lastpos = p[lastReadInd] + tg - (h[i] - p[lastReadInd]);
      lastpos = max(lastpos, h[i] + (tg - (h[i] - p[lastReadInd])) / 2);
    } else {
      return false;
    }
    while (p[lastReadInd] <= lastpos) {
      if (lastReadInd == m) return true;
      lastReadInd++;
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", h + i);
  }
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", p + i);
  }
  long long mi = 0;
  long long ma = 2e11;
  while (mi < ma) {
    long long mid = (mi + ma) / 2;
    if (!CanRead(mid)) {
      mi = mid + 1;
    } else {
      ma = mid;
    }
  }
  cout << ma;
}
