#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)(1e9 + 7);
const long long N = (long long)(1e5 + 7);
long long p[N];
long long h[N];
int n, m;
bool fun(long long dist) {
  queue<long long> q;
  for (int i = 0; i < m; i++) {
    q.push(p[i]);
  }
  for (int i = 0; i < n; i++) {
    if (q.empty()) {
      return true;
    }
    if (q.front() >= h[i]) {
      while (!q.empty() && q.front() <= h[i] + dist) {
        q.pop();
      }
    } else {
      long long x = h[i] - q.front();
      if (x > dist) {
        return false;
      }
      long long y = max(dist - (2 * x), (dist - x) / 2);
      y = max(y, (long long)0);
      while (!q.empty() && q.front() <= h[i]) {
        q.pop();
      }
      while (!q.empty() && q.front() - h[i] <= y) {
        q.pop();
      }
    }
  }
  if (q.empty()) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  sort(h, h + n);
  sort(p, p + m);
  long long l = 0;
  long long r = 20000000007;
  long long ans = -1;
  while (l <= r) {
    long long dist = (l + r) / 2;
    if (fun(dist)) {
      ans = dist;
      r = dist - 1;
    } else {
      l = dist + 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
