#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100004;
long long h[NMAX], p[NMAX], cnt[NMAX], a[NMAX];
int n, m;
inline bool Check(const long long x) {
  int j = 1;
  long long maxx = -1;
  for (int i = (1); i <= (n); ++i) {
    while (j <= m && p[j] <= maxx) ++j;
    if (j > m) return true;
    if (h[i] <= p[j])
      maxx = h[i] + x;
    else {
      if (h[i] - p[j] > x) return false;
      maxx = max(maxx,
                 max(p[j] + x - (h[i] - p[j]), h[i] + (x - (h[i] - p[j])) / 2));
    }
  }
  while (j <= m && p[j] <= maxx) ++j;
  if (j > m) return true;
  return false;
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);
  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 sol = -1, L = 0, R = 1LL << 60, mid;
  while (L <= R) {
    mid = (L + R) / 2;
    if (Check(mid)) {
      sol = mid;
      R = mid - 1;
    } else
      L = mid + 1;
  }
  cout << sol << "\n";
  return 0;
}
