#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100005], b[100005];
bool check(long long mid) {
  long long xy;
  int pos = 1;
  for (int i = 1; i <= n; i++) {
    xy = 0;
    if (pos > m) return true;
    if (a[i] - b[pos] > mid) return false;
    if (b[pos] < a[i]) {
      xy = max(xy, b[pos] + (mid - (a[i] - b[pos])));
      xy = max(xy, a[i] + (mid - (a[i] - b[pos])) / 2);
    } else
      xy = a[i] + mid;
    while (pos <= m && b[pos] <= xy) pos++;
  }
  if (pos > m) return true;
  return false;
}
void init() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%lld", &b[i]);
  long long A = 0, B = 100000000000ll, mid, ans;
  while (A <= B) {
    mid = A + B >> 1ll;
    if (check(mid))
      ans = mid, B = mid - 1ll;
    else
      A = mid + 1ll;
  }
  printf("%lld", ans);
}
int main() {
  init();
  return 0;
}
