#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
const int M = 27;
int n, m;
long long h[N], p[N];
bool can(long long t) {
  queue<long long> q;
  for (int i = 0; i < m; i++) q.push(p[i]);
  for (int i = 0; i < n; i++) {
    long long top = q.front();
    long long lft = h[i], rgt = h[i];
    if (top < h[i]) lft = top;
    if (h[i] - lft > t) return 0;
    rgt = max(h[i] + t - 2LL * (h[i] - lft), h[i] + (t - (h[i] - lft)) / 2LL);
    while (q.size() && q.front() <= rgt) q.pop();
    if (!q.size()) break;
  }
  if (int(q.size())) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
  long long low = 0, high = 1e11;
  while (low + 1LL < high) {
    long long mid = (low + high) / (2 * 1LL);
    if (can(mid))
      high = mid;
    else
      low = mid + 1LL;
  }
  if (can(low))
    cout << low;
  else
    cout << high;
  return 0;
}
