#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5;
long long n, m, h[N], p[N];
bool good(long long t) {
  long long pind = 0;
  for (long long i = 0; i < n; i++) {
    long long d = max(h[i] - p[pind], 0ll);
    if (d > t) return 0;
    long long mm = max(t - 2 * d, (t - d) / 2);
    pind = upper_bound(p, p + m, h[i] + mm) - p;
    if (pind == m) return 1;
  }
  return 0;
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> h[i];
  for (long long i = 0; i < m; i++) cin >> p[i];
  long long l = -1, h = 2e10;
  while (h - l > 1) {
    long long m = h + l >> 1;
    (good(m) ? h : l) = m;
  }
  cout << h << endl;
}
