#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long h[100010], p[100010];
int n, m;
bool ok(long long mid) {
  int g = 0, j;
  for (int i = 0; i < n; i++) {
    long long x = h[i];
    for (j = g; j < m; j++) {
      long long tmp = (p[j] - p[g]) + min(abs(p[g] - x), abs(p[j] - x));
      if (tmp > mid) {
        g = j;
        break;
      }
    }
    if (j >= m) return 1;
  }
  return 0;
}
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];
  long long l = 0, r = 2e10, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (ok(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
