#include <bits/stdc++.h>
const long long inf = 5e10;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T, class T2>
void smin(T& a, T2 val) {
  if (a > val) a = val;
}
template <class T, class T2>
void smax(T& a, T2 val) {
  if (a < val) a = val;
}
const long long N = (long long)1e5 + 10;
long long n, h[N], m, p[N];
bool f(long long time) {
  long long ptr = 0;
  long long mx = 0;
  long long curr = 0;
  while (curr < m) {
    long long x = p[curr];
    ++curr;
    if (x <= mx) {
      continue;
    }
    if (ptr == n) {
      return false;
    }
    long long i;
    for (i = ptr; i < n; ++i) {
      if (h[i] <= x) {
        smax(mx, h[i] + time);
        if (mx >= x) {
          ptr = i + 1;
          break;
        }
      } else {
        if (h[i] - x > time) {
          continue;
        } else {
          long long A = h[i] + (time - (h[i] - x)) / 2;
          long long B = time - 2 * (h[i] - x) + h[i];
          smax(mx, max(A, B));
          ptr = i + 1;
          break;
        }
      }
    }
    if (i == n) {
      return false;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < n; ++i) {
    cin >> h[i];
  }
  for (long long i = 0; i < m; ++i) {
    cin >> p[i];
  }
  long long low = 0, high = inf, ans = inf;
  while (low <= high) {
    long long mid = (low + high) >> 1;
    if (f(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
  return 0;
}
