#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
long long a[N], b[N], l, r, mid;
inline bool check(long long x) {
  int last = 1;
  for (int i = 1; i <= n; i++) {
    if (last > m) {
      return true;
    }
    if (b[last] >= a[i]) {
      while (last <= m && b[last] - a[i] <= x) {
        last++;
      }
    } else {
      if (a[i] - b[last] > x) {
        return false;
      }
      int lejat = last + 1;
      for (int j = last; j <= m; j++) {
        if (b[j] <= a[i]) {
          lejat = j + 1;
        } else {
          long long l1, l2;
          l1 = a[i] - b[last];
          l2 = b[j] - a[i];
          if (min(l1 * 2 + l2, l2 * 2 + l1) > x) {
            break;
          }
          lejat = j + 1;
        }
      }
      last = lejat;
    }
  }
  return last > m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  l = 0, r = 1e16;
  while (r - l > 1) {
    mid = (r + l) >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (check(l)) {
    cout << l;
  } else {
    cout << r;
  }
}
