#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100010], p[100010];
long long llabs(long long val1, long long val2) {
  if (val1 > val2) return val1 - val2;
  return val2 - val1;
}
bool check(long long d) {
  int i, j;
  long long dis, val1, val2;
  j = 0;
  for (i = 0; i < n; i++) {
    if (llabs(h[i], p[j]) > d) continue;
    if (h[i] <= p[j]) {
      while (j < m && llabs(h[i], p[j]) <= d) j++;
      continue;
    }
    dis = h[i] - p[j];
    while (j < m && p[j] < h[i]) j++;
    while (j < m) {
      val1 = dis * 2ll + (p[j] - h[i]);
      val2 = dis + (p[j] - h[i]) * 2ll;
      if (val1 > d && val2 > d) break;
      j++;
    }
  }
  return j == m;
}
void solve() {
  int i, j;
  long long dau, cuoi, giua, ans;
  dau = 0;
  cuoi = (1LL << 50);
  while (dau <= cuoi) {
    giua = (dau + cuoi) >> 1;
    if (check(giua)) {
      ans = giua;
      cuoi = giua - 1;
    } else
      dau = giua + 1;
  }
  cout << ans << endl;
}
void input() {
  int i;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) cin >> h[i];
  for (i = 0; i < m; i++) cin >> p[i];
  solve();
}
int main() {
  input();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
