#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[1000005], p[1000005];
int main() {
  ios::sync_with_stdio(false);
  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 = -1, r = 100000000000LL;
  while (r - l > 1LL) {
    long long testnum = (r + l) >> 1;
    int last = 0;
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (h[i] - p[last] > testnum) {
        ok = 0;
        break;
      }
      int j;
      for (j = last; j < m; j++) {
        if (abs(p[j] - h[i]) + p[j] - p[last] <= testnum ||
            abs(h[i] - p[last]) + p[j] - p[last] <= testnum)
          continue;
        break;
      }
      if ((last = j) == m) break;
    }
    if (!ok || last < m)
      l = testnum;
    else
      r = testnum;
  }
  cout << r << endl;
  return 0;
}
