#include <bits/stdc++.h>
using namespace std;
vector<long long> h, p;
long long check(long long m) {
  long long j = 0;
  for (long long i = 0; i < h.size(); i++) {
    long long low = j;
    long long high = ((long long)p.size()) - 1;
    while (low <= high) {
      long long mid = (low + high) / 2;
      long long t =
          p[mid] - p[j] + min(llabs(h[i] - p[j]), llabs(h[i] - p[mid]));
      if (t > m)
        high = mid - 1;
      else
        low = mid + 1;
    }
    j = low;
  }
  return j;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  while (cin >> n >> m) {
    for (long long i = 1; i <= n; i++) {
      long long a;
      cin >> a;
      h.push_back(a);
    }
    for (long long i = 1; i <= m; i++) {
      long long a;
      cin >> a;
      p.push_back(a);
    }
    long long low = 0;
    long long high = 1000000000000;
    while (low <= high) {
      long long mid = (low + high) / 2;
      if (check(mid) >= m)
        high = mid - 1;
      else
        low = mid + 1;
    }
    cout << low << endl;
    h.clear();
    p.clear();
  }
  return 0;
}
