#include <bits/stdc++.h>
using namespace std;
long long n, m, p[200000], h[200000];
bool ok(long long x) {
  long long l = 0, r = 0;
  while (l < n && r < m) {
    long long y = p[r];
    while (min(abs(h[l] - p[r]), abs(h[l] - y)) + p[r] - y <= x) {
      r++;
      if (r == m) return true;
    }
    l++;
  }
  if (r < m) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < m; i++) cin >> p[i];
  long long l = 0, r = 10e15;
  while (r - l > 2) {
    long long mid = (r + l) / 2;
    if (ok(mid))
      r = mid;
    else
      l = mid;
  }
  for (long long i = l; i <= r; i++)
    if (ok(i)) {
      cout << i;
      return 0;
    }
}
