#include <bits/stdc++.h>
using namespace std;
long long l, r, mid, n, m, last;
long long a[100010], b[100010];
bool check() {
  int now = 1;
  for (int i = 1; i <= n; i++) {
    last = now;
    while (min(abs(b[last] - a[i]), abs(b[now] - a[i])) +
                   abs(b[last] - b[now]) <=
               mid &&
           last <= m)
      last++;
    now = last;
  }
  if (now > m)
    return true;
  else
    return false;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  l = 0;
  r = 20000000000LL;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check())
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
