#include <bits/stdc++.h>
const int maxn = 1e5;
int n, m;
long long h[maxn + 10], p[maxn + 10];
long long l = 0, r = 0;
inline long long get_tim(int x, int l, int r) {
  long long posx = h[x], posl = p[l], posr = p[r];
  if (posx <= posl) {
    return posr - posx;
  } else if (posr <= posx) {
    return posx - posl;
  } else {
    long long l1 = posx - posl, l2 = posr - posx;
    if (l1 > l2) std::swap(l1, l2);
    return l1 * 2 + l2;
  }
}
inline bool check(long long mid) {
  int j1 = 1, j2 = 1;
  for (register int i = 1; i <= n; ++i) {
    long long tim = get_tim(i, j1, j2);
    while (tim <= mid) {
      ++j2;
      if (j2 == m + 1) return 1;
      tim = get_tim(i, j1, j2);
    }
    j1 = j2;
  }
  return false;
}
signed main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= n; ++i) {
    scanf("%lld", &h[i]);
  }
  for (register int i = 1; i <= m; ++i) {
    scanf("%lld", &p[i]);
  }
  r = std::abs(p[1] - h[1]) * 2 + std::abs(p[m] - h[1]) * 2 + 100;
  long long re = 0;
  for (register long long mid = (l + r) >> 1; l <= r; mid = (l + r) >> 1) {
    bool res = check(mid);
    if (res) {
      re = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%lld\n", re);
}
