#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100005], p[100005], ans;
bool solve(long long t) {
  int pos = 1;
  for (int i = 1; i <= n && pos <= m; ++i) {
    if (h[i] - p[pos] > t) break;
    long long y = 0;
    if (p[pos] > h[i])
      y = t;
    else
      y = max((t - (h[i] - p[pos])) / 2, t - 2 * (h[i] - p[pos]));
    while (pos <= m && p[pos] <= h[i] + y) pos++;
  }
  return pos == m + 1;
}
void cb() {
  long long l = 0, r = 2LL * 100005 * 100005;
  while (l <= r) {
    long long m = (l + r) / 2;
    if (solve(m)) {
      ans = m;
      r = m - 1;
    } else
      l = m + 1;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> h[i];
  for (int i = 1; i <= m; ++i) cin >> p[i];
  cb();
  cout << ans;
  return 0;
}
