#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int elLibraryDihBayza;
long long headers[MAXN + 5], track[MAXN + 5];
int H, T;
bool check(long long tim) {
  int h, t = 0, t2;
  for (h = 0; h < H && t < T; h++) {
    for (t2 = t; t2 < T; t2++) {
      long long A = headers[h] - min(headers[h], track[t]);
      long long B = max(track[t2], headers[h]) - headers[h];
      if (min(A, B) * 2LL + max(A, B) > tim) break;
    }
    t = t2;
  }
  return t == T;
}
int main() {
  int c, c2;
  scanf("%d%d", &H, &T);
  for (c = 0; c < H; c++) scanf("%I64d", &headers[c]);
  for (c = 0; c < T; c++) scanf("%I64d", &track[c]);
  long long s = 0, e = 2LL * max(track[T - 1], headers[H - 1]);
  long long ret;
  while (s <= e) {
    long long mid = (s + e) >> 1;
    if (check(mid)) {
      ret = mid;
      e = mid - 1;
    } else
      s = mid + 1;
  }
  printf("%I64d\n", ret);
  return 0;
}
