#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100100;
int N, M;
long long h[MAX_N], p[MAX_N];
inline long long calc(long long start, long long from, long long to) {
  if (to <= start) return start - from;
  if (from >= start) return to - start;
  long long left = start - from, right = to - start;
  long long mn = min(left, right), mx = max(left, right);
  return 2 * mn + mx;
}
inline bool check(long long dist) {
  int firstTrack = 1, lastTrack;
  for (int i = 1; i <= N; i += 1) {
    if (abs(p[firstTrack] - h[i]) > dist) {
      continue;
    }
    lastTrack = firstTrack;
    while (lastTrack < M &&
           calc(h[i], p[firstTrack], p[lastTrack + 1]) <= dist) {
      lastTrack += 1;
    }
    if (lastTrack == M) {
      return true;
    }
    firstTrack = lastTrack + 1;
  }
  return false;
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i += 1) {
    cin >> h[i];
  }
  for (int i = 1; i <= M; i += 1) {
    cin >> p[i];
  }
  long long answer = -1;
  for (long long bit = (1LL << 40); bit > 0; bit /= 2) {
    if (!check(answer + bit)) {
      answer += bit;
    }
  }
  cout << answer + 1 << endl;
  return 0;
}
