#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;
const long long int INFl = 4e18 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> h(n + 4);
  vector<long long int> p(m + 4);
  long long int mxp = -1, mxh = -1;
  long long int mnh = 2e18, mnp = 2e18;
  for (int i = 1; i <= n; i++)
    cin >> h[i], mnh = min(mnh, h[i]), mxh = max(mxh, h[i]);
  for (int i = 1; i <= m; i++)
    cin >> p[i], mxp = max(mxp, p[i]), mnp = min(mnp, p[i]);
  int i = 1, j = 1;
  vector<pair<long long int, int> > pos;
  int toRead = 0;
  while (i <= n && j <= m) {
    if (h[i] > p[j]) {
      ++toRead;
      pos.push_back({p[j], 1});
      j++;
    } else if (h[i] < p[j]) {
      pos.push_back({h[i], 0});
      i++;
    } else {
      pos.push_back({h[i], 0});
      i++, j++;
    }
  }
  while (i <= n) pos.push_back({h[i], 0}), i++;
  while (j <= m) pos.push_back({p[j], 1}), j++, ++toRead;
  long long int l = 1, r = 4ll * max(abs(mnh - mxp), abs(mnh - mnp));
  long long int ans = 0;
  if (toRead == 0) {
    cout << 0 << "\n";
    return 0;
  }
  while (l <= r) {
    long long int mid = (l + r) >> 1;
    long long int back = -1;
    int flag = 0;
    int len = pos.size();
    int posbl = 1;
    for (int i = 0; i < len; i++) {
      auto pr = pos[i];
      long long int x = pr.first;
      int y = pr.second;
      if (y == 1) {
        if (x > back && flag == 0) flag = 1, back = x;
      } else {
        if (back == -1) {
          back = mid + x;
          continue;
        } else if (back >= x)
          back = max(back, x + mid);
        else if (flag == 0)
          back = x + mid;
        else if (mid < x - back) {
          posbl = 0;
          break;
        } else {
          back =
              max((mid - (x - back)) / 2ll + x, mid - (2ll * (x - back)) + x);
        }
        flag = 0;
      }
    }
    if (flag == 1) posbl = 0;
    if (posbl == 1) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << "\n";
  return 0;
}
