#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 123456;
long long h[maxn], p[maxn];
int ok(long long t) {
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (cur >= m) break;
    long long pos = h[i];
    if (h[i] - p[cur] > t) return 0;
    if (h[i] < p[cur])
      pos += t;
    else {
      pos = max(h[i] + t - 2 * (h[i] - p[cur]),
                (h[i] + (t - (h[i] - p[cur])) / 2));
    }
    while (cur < m && p[cur] <= pos) cur++;
  }
  return cur >= m;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < m; i++) cin >> p[i];
  long long l = 0, r = (1ll) << 40;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (ok(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
