#include <bits/stdc++.h>
using namespace std;
long long h[100010], p[100010];
int main() {
  long long n, m;
  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 first = 0, last = max(2 * p[m - 1], max(h[n - 1], p[m - 1]));
  long long mid;
  while (first < last) {
    mid = (last - first) / 2 + first;
    bool flag = 1;
    double right = -1;
    int j = 0;
    for (int i = 0; i < n; i++) {
      while (j < m && right >= p[j]) j++;
      if (p[j] > h[i])
        right = h[i] + mid;
      else if (mid >= h[i] - p[j] || mid >= 2.0 * (h[i] - p[j]))
        right =
            h[i] + max((mid - h[i] + p[j]) / 2.0, mid - 2.0 * (h[i] - p[j]));
    }
    while (j < m && right >= p[j]) j++;
    if (j >= m)
      last = mid;
    else
      first = mid + 1;
  }
  cout << (last - first) / 2 + first << endl;
  return 0;
}
