#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
double pi = 3.141592653589793238;
const int M = 1000000007;
const int Nmax = 5005;
const int MM = 998244353;
const int N = 200050;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int T = 1;
  while (T--) {
    long long int n, m;
    cin >> n >> m;
    long long int h[n], p[m];
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < m; i++) cin >> p[i];
    long long int l = 0, r = 2e10, ans;
    while (l <= r) {
      long long int mid = (l + r) >> 1;
      bool ok = 1;
      long long int k = -1;
      for (int i = 0; i < n; i++) {
        long long int x = *lower_bound(p, p + m, k + 1);
        if (h[i] - x > mid) {
          ok = 0;
          break;
        }
        if (x <= h[i]) {
          long long int f = (mid - 2 * (h[i] - x));
          long long int g = (mid - (h[i] - x)) / 2;
          k = max(h[i], h[i] + f);
          k = max(k, h[i] + g);
        } else {
          k = max(k, h[i] + mid);
        }
        if (k >= p[m - 1]) break;
      }
      if (k < p[m - 1]) ok = 0;
      if (ok) {
        ans = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
