#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100100], b[100100];
inline bool Ok(long long T) {
  int i, j;
  long long final;
  for (i = j = 1; i <= n && j <= m; ++i) {
    if (a[i] <= b[j])
      final = a[i] + T;
    else {
      if (a[i] - b[j] > T) return false;
      final = a[i] + max(T - 2LL * (a[i] - b[j]), (T - (a[i] - b[j])) / 2);
    }
    while (j <= m && b[j] <= final) j++;
  }
  return (j > m);
}
inline long long BinarySearch() {
  long long st, dr, mij, rez;
  st = 0;
  dr = rez = 20000000000LL;
  while (st <= dr) {
    mij = (st + dr) / 2LL;
    if (Ok(mij)) {
      rez = mij;
      dr = mij - 1;
    } else
      st = mij + 1;
  }
  return rez;
}
int main() {
  int i;
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> b[i];
  cout << BinarySearch() << "\n";
  return 0;
}
