#include <bits/stdc++.h>
using namespace std;
long long h[100005], p[100005];
int n, m;
bool ok(long long t) {
  for (int i = 0, j = 0; i < n && j < m; ++i) {
    if (h[i] < p[j]) {
      while (j < m && h[i] + t >= p[j]) ++j;
    } else {
      if (h[i] - t > p[j]) break;
      long long st = p[j];
      while (j < m && h[i] >= p[j]) ++j;
      while (j < m && p[j] - st + min(p[j] - h[i], h[i] - st) <= t) ++j;
    }
    if (j == m) return 1;
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  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 = 0, high = 20000000000LL;
  while (low < high) {
    long long mid = (low + high) >> 1;
    if (ok(mid))
      high = mid;
    else
      low = mid + 1;
  }
  printf("%I64d\n", high);
  return 0;
}
