#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
long long a[100005], p[100005];
long long n, m;
bool check(long long mid) {
  long long last = 0;
  for (long long i = 0; i < (long long)n; i++) {
    if (last == m) return true;
    if (p[last] > a[i]) {
      while (last < m && p[last] - a[i] <= mid) last++;
      continue;
    }
    long long mn = a[i] - mid;
    if (mn > p[last]) return false;
    long long id1 =
        upper_bound(p, p + m, a[i] + mid - 2 * (a[i] - p[last])) - p;
    long long id2 =
        upper_bound(p, p + m, a[i] + (mid - (a[i] - p[last])) / 2) - p;
    last = max(last, id1);
    last = max(last, id2);
  }
  return (last == m);
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  ;
  cin >> n >> m;
  for (long long i = 0; i < (long long)n; i++) cin >> a[i];
  for (long long i = 0; i < (long long)m; i++) cin >> p[i];
  long long ans, low = 0, high = 1e18, mid;
  while (low <= high) {
    mid = (low + high) / 2;
    if (check(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans << "\n";
}
