#include <bits/stdc++.h>
int n, m;
long long a[100010], b[100010];
inline long long max(long long a, long long b) { return a > b ? a : b; }
bool check(long long t) {
  int j = 0;
  long long d, x;
  for (int i = 0; i < n; ++i) {
    d = a[i] - b[j];
    if (d > 0) {
      if (d > t) continue;
      x = a[i] + max((t - d) >> 1, t - (d << 1));
    } else {
      x = a[i] + t;
    }
    while (x >= b[j])
      if (++j == m) return true;
  }
  return false;
}
long long bs() {
  long long l = 0, r = 2e10, mid;
  while (l < r) {
    if (check(mid = l + r >> 1))
      r = mid;
    else
      l = mid + 1;
  }
  return l;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%I64d", a + i);
  for (int i = 0; i < m; ++i) scanf("%I64d", b + i);
  printf("%I64d", bs());
  return 0;
}
