#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1e5 + 5;
int n, m;
long long a[N], b[N];
bool f(long long x) {
  int last = 1;
  for (int i = 1; i <= n; i++) {
    if (last <= m and a[i] - b[last] > x) return 0;
    if (last <= m and b[last] < a[i]) {
      int next = upper_bound(b + last, b + m + 1, a[i]) - b;
      if (next <= m and (a[i] - b[last]) * 2 + b[next] - a[i] > x and
          a[i] - b[last] + (b[next] - a[i]) * 2 > x) {
        last = next;
        continue;
      }
      while (next <= m and ((a[i] - b[last]) * 2 + b[next] - a[i] <= x or
                            a[i] - b[last] + (b[next] - a[i]) * 2 <= x))
        next++;
      last = next;
    } else
      while (last <= m and b[last] - a[i] <= x) last++;
  }
  return last > m;
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  long long l = 0, r = 2e10;
  while (l < r) {
    long long m = l + r >> 1;
    if (f(m))
      r = m;
    else
      l = m + 1;
  }
  cout << l << '\n';
  return 0;
}
