#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100010], x, s, e, r, mid, ans, rem, t, d;
set<long long> a, b;
set<long long>::iterator it;
bool can(long long mid) {
  b = a;
  for (int i = 0; i < n; ++i) {
    if (b.empty()) return true;
    x = *b.begin();
    if (x < h[i]) {
      t = h[i] - x;
      if (t > mid) return false;
      while (!b.empty() && *b.begin() <= h[i]) b.erase(b.begin());
      while (!b.empty() && ((2 * t + *b.begin() - h[i] <= mid) ||
                            (t + 2 * (*b.begin() - h[i]) <= mid))) {
        b.erase(b.begin());
      }
    } else {
      while (!b.empty() && *b.begin() - h[i] <= mid) b.erase(b.begin());
    }
  }
  return b.empty();
}
int main(int argc, char **argv) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", &h[i]);
  for (int i = 0; i < m; ++i) {
    scanf("%lld", &x);
    a.insert(x);
  }
  s = 0, e = 1e12, ans = 0;
  while (s <= e) {
    mid = (s + e) / 2;
    if (can(mid)) {
      ans = mid;
      e = mid - 1;
    } else
      s = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
