#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long h[maxn], p[maxn];
int n, m;
int solve(long long t) {
  int i = 0, j = 0;
  long long last = -1;
  while (i < m) {
    if (p[i] <= last) {
      i++;
    } else {
      if (j == n) return 0;
      if (p[i] < h[j]) {
        if (h[j] - p[i] > t) return 0;
        last = max(last, h[j] + t - 2 * (h[j] - p[i]));
        last = max(last, h[j]);
        last = max(last, h[j] + (t - (h[j] - p[i])) / 2);
        i++;
      } else {
        last = max(last, h[j] + t);
        if (p[i] <= last) i++;
      }
      j++;
    }
  }
  return 1;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
    for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
    long long L = 0, R = 2e10 + 100;
    while (L < R) {
      long long mid = (L + R) / 2;
      if (solve(mid))
        R = mid;
      else
        L = mid + 1;
    }
    printf("%I64d\n", R);
  }
  return 0;
}
