#include <bits/stdc++.h>
using namespace std;
long long a[111111];
long long b[111111];
int main() {
  int n, m, i;
  int n1, m1;
  long long ll, rr, mm;
  long long wei;
  long long max;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  ll = 0;
  rr = 20000000001l;
  while (ll < rr) {
    n1 = 0;
    m1 = 0;
    mm = (ll + rr) / 2;
    for (n1 = 0; n1 < n; n1++) {
      if (b[m1] < a[n1]) {
        if (mm < a[n1] - b[m1]) break;
        wei = a[n1] + mm - 2 * (a[n1] - b[m1]);
        max = wei;
        wei = a[n1] + (mm - a[n1] + b[m1]) / 2;
        if (wei > max) max = wei;
        wei = max;
      } else {
        wei = a[n1] + mm;
      }
      while (m1 < m && wei >= b[m1]) m1++;
      if (m1 >= m) break;
    }
    if (m1 >= m) {
      rr = mm;
    } else {
      ll = mm + 1;
    }
  }
  cout << ll << endl;
  return 0;
}
