#include <bits/stdc++.h>
using namespace std;
long long awl = 0, akh = 0x7fffffffffffffff, h[100005], t[100005];
int i, n, m;
bool jalan(long long time) {
  int a = 1, b = 1;
  for (i = 1; i <= (n); i += 1) {
    while ((b < m + 1) &&
           ((min(abs(h[i] - t[a]), abs(h[i] - t[b])) + t[b] - t[a]) <= time)) {
      b++;
    }
    if (b == m + 1) return true;
    a = b;
  }
  return false;
}
int main() {
  long long tgh;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= (n); i += 1) scanf("%I64d", &h[i]);
  for (i = 1; i <= (m); i += 1) scanf("%I64d", &t[i]);
  while (akh > awl) {
    tgh = (awl + akh) >> 1;
    if (jalan(tgh))
      akh = tgh;
    else
      awl = tgh + 1;
  }
  printf("%I64d\n", akh);
  return 0;
}
