#include <bits/stdc++.h>
using namespace std;
int N, M;
long long Hi[100000], Pi[100000];
void read();
void solve();
bool check(long long);
int main() {
  read();
  solve();
  return 0;
}
void read() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> Hi[i];
  for (int i = 0; i < M; ++i) cin >> Pi[i];
}
void solve() {
  long long low = 0, up = 2 * (abs(Hi[0] - Pi[0]) + abs(Hi[0] - Pi[M - 1])),
            mid;
  while (low < up) {
    mid = (low + up) / 2;
    if (check(mid))
      up = mid;
    else
      low = mid + 1;
  }
  cout << low << "\n";
}
bool check(long long bnd) {
  deque<long long> q1, q2;
  q1.insert(q1.end(), &Hi[0], &Hi[N]);
  q2.insert(q2.end(), &Pi[0], &Pi[M]);
  while (!q1.empty()) {
    long long fn = q1.front();
    if (!q2.empty()) {
      if (fn > q2.front()) {
        if (fn - q2.front() > bnd) return false;
        int i;
        for (i = 0; i < int((q2).size()); ++i) {
          long long c;
          if (q2[i] <= fn)
            c = fn - q2.front();
          else
            c = (q2[i] - q2.front()) + min(q2[i] - fn, fn - q2.front());
          if (c > bnd) break;
        }
        while (i) {
          q2.pop_front();
          --i;
        }
      } else {
        while (!q2.empty() && bnd >= q2.front() - fn) q2.pop_front();
      }
    }
    q1.pop_front();
  }
  return q2.empty();
}
