#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long d[n], t[m];
  for (long long i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (long long j = 0; j < m; j++) {
    cin >> t[j];
  }
  long long l = 0, r = pow(10, 11), ans = LLONG_MAX;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long flag = 0;
    long long j = 0;
    for (long long i = 0; i < n && j < m; i++) {
      if (d[i] <= t[j]) {
        while (j < m && t[j] <= d[i] + mid) {
          j++;
        }
      } else {
        if (d[i] - mid > t[j]) {
          flag = 1;
          break;
        }
        long long cnt1 = 0, cnt2 = 0, ind1 = j, ind2 = j;
        while (ind1 < m && t[ind1] <= d[i]) {
          ind1++;
          cnt1++;
          cnt2++;
          ind2++;
        }
        while (ind1 < m && (t[ind1] <= d[i] + mid - 2 * (d[i] - t[j]))) {
          ind1++;
          cnt1++;
        }
        while (ind2 < m && (t[ind2] <= d[i] + ((mid - (d[i] - t[j])) / 2))) {
          ind2++;
          cnt2++;
        }
        if (cnt1 > cnt2) {
          j = ind1;
        } else {
          j = ind2;
        }
      }
    }
    if (flag || j < m) {
      l = mid + 1;
    } else {
      ans = min(ans, mid);
      r = mid - 1;
    }
  }
  cout << ans << endl;
}
