#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
const int linf = 2000000000;
const long long llinf = 1000000000000000000ll;
vector<long long> p, t;
set<long long> check;
int main() {
  int n, m;
  long long ans = 10000000000000ll;
  long long temp;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    check.insert(temp);
    p.push_back(temp);
  }
  for (int i = 0; i < m; ++i) {
    cin >> temp;
    if (check.find(temp) == check.end()) t.push_back(temp);
  }
  int sz = t.size();
  long long l = 0, r = 10000000000000ll;
  while (l <= r) {
    long long m = (l + r) >> 1;
    int c1 = 0, c2 = 0;
    while (c1 < n && c2 < sz) {
      if (p[c1] > t[c2]) {
        if (p[c1] - t[c2] > m) {
          break;
        } else {
          long long next = c2;
          long long ost1 = m - 2 * (p[c1] - t[c2]);
          long long ost2 = (m - (p[c1] - t[c2])) / 2;
          long long n1 = c2 + 1, n2 = c2 + 1;
          while (n1 < sz && (p[c1] > t[n1] || t[n1] - p[c1] <= ost1)) {
            ++n1;
          }
          while (n2 < sz && (p[c1] > t[n2] || t[n2] - p[c1] <= ost2)) {
            ++n2;
          }
          c2 = max(n1, n2);
        }
      } else {
        while (c2 < sz && t[c2] - p[c1] <= m) {
          ++c2;
        }
      }
      ++c1;
    }
    if (c2 >= sz) {
      bool cl = false;
      if (l == r) cl = true;
      r = m;
      ans = min(m, ans);
      if (cl) break;
    } else {
      l = m + 1;
    }
  }
  cout << ans;
  return 0;
}
