#include <bits/stdc++.h>
using namespace std;
const int maxn = 101000;
long long n, m, a[maxn], b[maxn];
bool check(long long x) {
  int head = 1, tail;
  for (int i = 1; i <= n && head <= m; i++) {
    if (abs(a[i] - b[head]) > x) continue;
    if (b[head] < a[i]) {
      tail = head + 1;
      while (min(2 * (a[i] - b[head]) + b[tail] - a[i],
                 2 * (b[tail] - a[i]) + a[i] - b[head]) <= x)
        tail++;
      head = tail - 1;
    } else {
      while (b[head] - a[i] <= x) head++;
      head--;
    }
    head++;
  }
  return head > m;
}
int main() {
  cin >> n >> m;
  long long l = -1, r = 1e18, ans;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
