#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
long long n, m;
long long a[maxn], b[maxn];
bool f[maxn];
bool can(long long t);
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  long long l = 0, r, mid;
  r = 2 * abs((a[0] - b[0])) + b[m - 1];
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }
  if (can(l))
    cout << l << endl;
  else
    cout << r << endl;
  return 0;
}
bool can(long long t) {
  for (long long i = 0; i < m; i++) f[i] = 0;
  long long k = 0;
  for (long long i = 0; i < n; i++) {
    if (k >= m) break;
    if (a[i] - t <= b[k] && b[k] < a[i]) {
      long long tem = b[k];
      long long tem1 = 0;
      tem += t - (a[i] - b[k]);
      tem1 = a[i] + (t - (a[i] - b[k])) / 2;
      tem = max(tem, tem1);
      f[k] = true;
      k++;
      while (tem >= b[k]) {
        f[k] = true;
        k++;
        if (k >= m) break;
      }
    } else if (b[k] >= a[i]) {
      long long tem = a[i] + t;
      while (tem >= b[k]) {
        f[k] = true;
        k++;
        if (k >= m) break;
      }
    }
  }
  for (long long i = 0; i < m; i++) {
    if (!f[i]) return false;
  }
  return true;
}
