#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getInt(T &x) {
  char c = 0;
  T sign = 1;
  if ((c = getchar()) == EOF) {
    return false;
  }
  while ((c < '0' || c > '9') && c != '-') {
    c = getchar();
  };
  if (c == '-') {
    sign = -1;
    c = getchar();
  }
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') {
    x = x * 10 + c - '0';
  }
  x *= sign;
  return true;
}
long long n, m, h[100005], p[100005];
bool judge(long long t) {
  for (int i = 0, j, cur = 0; i < n; i++) {
    j = cur;
    while (j < m && min(abs(h[i] - p[cur]) + abs(p[cur] - p[j]),
                        abs(h[i] - p[j]) + abs(p[j] - p[cur])) <= t) {
      j++;
    }
    if (j == m) {
      return true;
    }
    cur = j;
  }
  return false;
}
int main() {
  while (getInt(n)) {
    getInt(m);
    for (int i = 0; i < n; i++) {
      getInt(h[i]);
    }
    for (int i = 0; i < m; i++) {
      getInt(p[i]);
    }
    long long l = -1, r = LLONG_MAX, mid;
    while (l + 1 < r) {
      mid = (l + r) / 2;
      if (judge(mid)) {
        r = mid;
      } else {
        l = mid;
      }
    }
    printf("%I64d\n", r);
  }
}
