#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 100003;
int n, m;
ll p[MAXN], h[MAXN];
bool check(ll v) {
  ll tmp, lb;
  int nid = 0;
  for (int i = 0; i < n; ++i) {
    if (nid == m) break;
    if (h[i] > p[nid]) {
      tmp = h[i] - p[nid];
      lb = max(v - 2 * tmp, (v - tmp) / 2ll);
      if (h[i] - p[nid] > v) return false;
      while (h[i] + lb >= p[nid]) nid++;
    } else {
      while (h[i] + v >= p[nid]) nid++;
    }
  }
  if (nid == m) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  while (cin >> n >> m) {
    for (int i = 0; i < n; ++i) cin >> h[i];
    for (int i = 0; i < m; ++i) cin >> p[i];
    p[m] = 20000000000000ll;
    ll l = 0, r = 30000000000ll, mid;
    while (l <= r) {
      mid = (l + r) / 2ll;
      if (check(mid)) {
        r = mid - 1ll;
      } else {
        l = mid + 1ll;
      }
    }
    cout << l << '\n';
  }
  return 0;
}
