#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string cts(char x) {
  string t(1, x);
  return t;
}
long long rand(long long a, long long b) { return a + rng() % (b - a + 1); }
const long long MOD = 1e9 + 7;
const long long inf = (long long)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T>
void chmax(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T& a, T b) {
  a = min(a, b);
}
const long long MAXN = 100005;
long long A[MAXN];
long long n, m;
vector<long long> heads;
bool check(long long ti) {
  long long idx = 1;
  for (auto i : heads) {
    long long d = A[idx];
    long long nxt = -oo;
    if (d >= i) {
      nxt = i + ti;
    } else {
      long long lf = i - d;
      if (lf > ti) return 0;
      chmax(nxt, i + (ti - lf * 2));
      chmax(nxt, i + (ti - lf) / 2);
    }
    while (idx <= m && A[idx] <= nxt) ++idx;
    if (idx == m + 1) return 1;
  }
  return idx == m + 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= (long long)n; ++i) {
    long long x;
    cin >> x;
    heads.push_back(x);
  }
  for (long long i = 1; i <= (long long)m; ++i) {
    cin >> A[i];
  }
  if (0) cout << check(3);
  long long lo = -1, hi = 1e11 + 1;
  while (lo < hi - 1) {
    long long mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid;
  }
  cout << hi;
}
