#include <bits/stdc++.h>
using namespace std;
vector<long long int> head, data;
long long int n, m;
bool check(long long int ans) {
  long long int prev = 0;
  long long int next;
  for (long long int i = 0; i < n; i++) {
    if (prev == m) return true;
    long long int cur = head[i];
    if (i == n - 1) {
      next = m - 1;
      long long int z;
      if (cur >= data[prev] && cur <= data[next])
        z = data[next] - data[prev] + min(cur - data[prev], data[next] - cur);
      else if (data[prev] > cur)
        z = data[next] - cur;
      else if (data[next] < cur)
        z = cur - data[prev];
      if (z <= ans)
        return true;
      else
        return false;
    } else {
      long long int l, r;
      l = prev - 1;
      r = m - 1;
      while (l < r) {
        long long int mid = (l + r + 1) / 2, z;
        if (cur >= data[prev] && cur <= data[mid])
          z = data[mid] - data[prev] + min(cur - data[prev], data[mid] - cur);
        else if (data[prev] > cur)
          z = data[mid] - cur;
        else if (data[mid] < cur)
          z = cur - data[prev];
        if (z <= ans)
          l = mid;
        else
          r = mid - 1;
      }
      prev = l + 1;
    }
  }
}
long long int binary() {
  long long int l, r;
  l = 0;
  r = 2 * 10000000005;
  while (l < r) {
    long long int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  return l;
}
int main() {
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    head.push_back(x);
  }
  for (long long int i = 0; i < m; i++) {
    long long int x;
    cin >> x;
    data.push_back(x);
  }
  data.push_back(LLONG_MAX);
  long long int ans = binary();
  cout << ans << '\n';
}
