#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
long long a[100005];
long long b[100005];
int n, m;
bool gao(long long x) {
  int cur = 0;
  for (int i = 0; i < n; i++) {
    if (abs(a[i] - b[cur]) > x) {
      continue;
    }
    long long tmp;
    if (a[i] == b[cur]) {
      cur++;
    }
    if (a[i] > b[cur]) {
      tmp =
          max(a[i] + x - (a[i] - b[cur]) * 2, (x - (a[i] - b[cur])) / 2 + a[i]);
    } else
      tmp = a[i] + x;
    while (cur < m && tmp >= b[cur]) cur++;
    if (cur == m) return true;
  }
  return cur == m;
}
int main() {
  scanf("%d%d", &n, &m);
  long long r = 0;
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int i = 0; i < m; i++) scanf("%lld", &b[i]), r += abs(a[0] - b[i]);
  r += abs(a[0] - b[0]);
  long long l = 0, ans = -1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (gao(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
