#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100009], p[100009];
bool judge(long long t) {
  int step = 0;
  for (int i = 0; i < n; i++) {
    if (step >= m) break;
    if (h[i] - p[step] > t) return false;
    long long s = h[i];
    if (h[i] < p[step])
      s = h[i] + t;
    else {
      s = max(s, h[i] + t - 2 * (h[i] - p[step]));
      s = max(s, h[i] + (t - (h[i] - p[step])) / 2);
    }
    while (step < m && p[step] <= s) step++;
  }
  if (step < m) return false;
  return true;
}
int main() {
  while (scanf("%d %d", &n, &m) == 2) {
    for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
    for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
    long long low = -1, high = -1;
    if (h[0] < p[0])
      high = p[m - 1] - h[0];
    else {
      high = max((h[0] - p[0]) * 2 + p[m - 1] - h[0],
                 (p[m - 1] - h[0]) * 2 + h[0] - p[0]);
    }
    while (high - low > 1) {
      long long mid = (high + low) >> 1;
      if (judge(mid))
        high = mid;
      else
        low = mid;
    }
    printf("%I64d\n", high);
  }
  return 0;
}
