#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
long long p[N], h[N];
bool check(int n, int m, long long T) {
  int last = 0;
  for (int i = 1; i <= n; i++) {
    if (last == m) return 1;
    long long pos = p[last + 1];
    long long cur = h[i];
    long long T1 = max(0LL, cur - pos);
    long long T2 = max(T - 2 * T1, (T - T1) / 2);
    if (T1 > T) return 0;
    while (last < m && p[last + 1] <= cur + T2) last++;
  }
  return last == m;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%lld", &h[i]);
  for (int i = 1; i <= m; i++) scanf("%lld", &p[i]);
  long long lo = -1, hi = 2e10 + 5;
  while (hi - lo > 1) {
    long long mid = lo + hi >> 1;
    if (check(n, m, mid))
      hi = mid;
    else
      lo = mid;
  }
  cout << hi << endl;
  return 0;
}
