#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long n, m, p[N], h[N];
bool can(long long x) {
  long long r = 0, i;
  for (i = 0; i < n && r < m; i++) {
    long long temp = r;
    while (r < m &&
           p[r] - p[temp] + min(abs(h[i] - p[temp]), abs(p[r] - h[i])) <= x)
      r++;
  }
  return (r == m);
}
int main() {
  long long i, l, r, mid;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> h[i];
  for (i = 0; i < m; i++) cin >> p[i];
  l = -1;
  r = 1e18;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }
  cout << ++l << "\n";
  return 0;
}
