#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 100001;
long long int h[maxn], r[maxn];
int check(long long int val) {
  long long int a = 0;
  long long int read = 0;
  for (int i = 0; i < n; i++) {
    long long int tmp;
    if (a == m) return 1;
    tmp = max(0ll, h[i] - r[a]);
    if (tmp > val) return 0;
    read = max((val - tmp) / 2, val - 2 * tmp);
    while (a < m && r[a] <= h[i] + read) a++;
  }
  if (a < m) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < m; i++) cin >> r[i];
  long long int lo = 0;
  long long int hi = 20000000000ll;
  long long int ans;
  while (lo <= hi) {
    long long int mi = (lo + hi) >> 1;
    if (check(mi)) {
      ans = mi;
      hi = mi - 1;
    } else {
      lo = mi + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
