#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int maxn = 1e5 + 10;
int n, m;
long long h[maxn];
long long p[maxn];
bool check(long long t) {
  long long vis = min(p[1], h[1]);
  long long add = 0;
  for (int i = 1; i <= n; i++) {
    vis = min(vis, h[i]);
    if (t < h[i] - vis) return false;
    add = max(t - 2 * (h[i] - vis), (t - (h[i] - vis)) / 2);
    if (add < 0) return false;
    long long val = h[i] + add;
    long long pos = upper_bound(p + 1, p + m + 1, val) - p;
    if (pos == m + 1) return true;
    vis = p[pos];
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> h[i];
  for (int i = 1; i <= m; i++) cin >> p[i];
  long long l = 0, r = 1e14, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
}
