#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100005], b[100005];
bool check(long long x) {
  int i, j, k;
  j = 0;
  for (i = 0; i < n; i++) {
    for (k = j; j < m; j++) {
      if ((b[j] - b[k] + min(abs(b[j] - a[i]), abs(b[k] - a[i]))) > x) break;
    }
    if (j == m) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &b[i]);
  long long mid;
  long long r = b[m - 1] - b[0] + abs(a[0] - b[0]);
  long long l = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
