#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using P = pair<int, int>;
const int INF = 1001001001;
const int mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n), p(m);
  for (int i = 0; i < (n); ++i) {
    cin >> h[i];
  }
  for (int i = 0; i < (m); ++i) {
    cin >> p[i];
  }
  auto f = [&](long long t) {
    long long r = p[0];
    for (int i = 0; i < (n); ++i) {
      long long x = 0;
      if (r < h[i] - t) {
        return false;
      } else if (r < h[i]) {
        long long L = h[i] - r;
        x = max(h[i], max(h[i] + t - L * 2, h[i] + (t - L) / 2));
      } else {
        x = h[i] + t;
      }
      int v = upper_bound(p.begin(), p.end(), x) - p.begin();
      if (v == m) {
        return true;
      }
      r = p[v];
    }
    return false;
  };
  long long l = -1, r = 1e18 * 2;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (f(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
  return 0;
}
