#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long head[100001];
long long block[100001];
long long t[100001];
bool isCan(long long time) {
  int bPos = 0;
  int hPos = 0;
  while (hPos < n) {
    long long left = head[hPos] - block[bPos];
    if (abs(left) > time) {
      hPos++;
      continue;
    }
    if (left < 0) left = 0;
    long long right = 0;
    while (2 * left + right <= time || 2 * right + left <= time) {
      if (bPos >= m || hPos >= n) break;
      bPos++;
      right = block[bPos] - head[hPos];
      if (right < 0) right = 0;
    }
    hPos++;
  }
  if (bPos >= m) return true;
  return false;
}
int main() {
  scanf("%lld %lld", &n, &m);
  for (int i = 0; i < n; i++) scanf("%lld", &head[i]);
  for (int i = 0; i < m; i++) scanf("%lld", &block[i]);
  long long low = 0;
  long long high = 1e11;
  long long ans = 1e11;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (isCan(mid)) {
      high = mid - 1;
      ans = min(ans, mid);
    } else
      low = mid + 1;
  }
  cout << ans;
  return 0;
}
