#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
const long long INF = LLONG_MAX / 2;
long long hi[maxn];
long long pi[maxn];
int N;
int M;
bool judge(long long val) {
  long long ans = 0;
  long long cur = 1;
  for (int i = 1; i <= N; i++) {
    if (cur > M) {
    }
    if (abs(hi[i] - pi[cur]) > val) {
      continue;
    }
    long long finish;
    if (hi[i] == pi[cur]) {
      cur++;
      finish = pi[cur] + val;
    } else if (hi[i] > pi[cur]) {
      finish = max(hi[i] + val - 2 * (hi[i] - pi[cur]),
                   hi[i] + (val - (hi[i] - pi[cur])) / 2);
    } else {
      finish = hi[i] + val;
    }
    while (cur <= M && finish >= pi[cur]) {
      cur++;
    }
  }
  if (cur <= M) {
    return false;
  } else {
    return true;
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    cin >> hi[i];
  }
  long long sum = 0;
  for (int i = 1; i <= M; i++) {
    cin >> pi[i];
  }
  long long l = 0;
  long long r = INF;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (judge(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
  return 0;
}
