#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int N, M;
ll a[MN], b[MN];
bool f(ll x) {
  ll j = 0, l, cur;
  for (int i = 0; i < N; i++) {
    cur = a[i], l = min(b[j], cur);
    if (cur - l > x) return false;
    while (b[j] <= cur && j < M) j++;
    while (min(2 * (b[j] - cur) + cur - l, b[j] - cur + 2 * (cur - l)) <= x &&
           j < M)
      j++;
    if (j == M) return true;
  }
  return j == M;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < M; i++) cin >> b[i];
  ll l = 0, r = 4e18;
  while (l < r) {
    ll m = (l + r) / 2;
    if (f(m))
      r = m;
    else
      l = m + 1;
  }
  cout << l << '\n';
  return 0;
}
