#include <bits/stdc++.h>
using namespace std;
int n, m;
long long head[1000010];
long long track[1000010];
bool check(long long t) {
  int cur = 0;
  for (int i = 0; i < n && cur < m; i++) {
    int pre = cur;
    while (cur < m &&
           min(abs(track[cur] - head[i]), abs(track[pre] - head[i])) +
                   track[cur] - track[pre] <=
               t)
      cur++;
  }
  return cur == m;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) scanf("%I64d", &head[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &track[i]);
  long long l = 0, r = 20000000000LL;
  while (l < r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
