#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<long long int> p(n);
  set<long long int> hs;
  for (int i = 0; i < n; ++i) {
    long long int x;
    cin >> x;
    p[i] = x;
  }
  for (int i = 0; i < m; ++i) {
    long long int x;
    cin >> x;
    hs.insert(x);
  }
  for (int i = 0; i < n; ++i) {
    hs.erase(p[i]);
  }
  vector<long long int> h(hs.begin(), hs.end());
  m = (int)h.size();
  vector<int> cp(n, m);
  int xx = 0;
  int yy = 0;
  while (xx < m) {
    while (yy < n && (p[yy] < h[xx])) {
      cp[yy] = xx;
      yy++;
    }
    xx++;
  }
  long long int l = -1, r = 1e13, mid;
  while (r - l > 1) {
    mid = (l + r) >> 1;
    int last = 0;
    for (int i = 0; i < n; ++i) {
      int j = last;
      for (; j < m; j++) {
        long long int t1 = abs(p[i] - h[j]);
        long long int t2 = abs(p[i] - h[last]);
        long long int t3 = min(t1, t2) + h[j] - h[last];
        if (t3 > mid) break;
      }
      last = j;
    }
    if (last == m) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r;
  return 0;
}
