#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 100;
int n, m;
long long h[N], p[N];
bool check(long long T) {
  int cur = 0;
  for (int i = 0; i < n && cur < m; i++) {
    if (h[i] <= p[cur]) {
      while (cur < m && p[cur] - h[i] <= T) ++cur;
    } else {
      if (h[i] - p[cur] > T) return false;
      long long x = p[cur];
      while (cur < m && p[cur] <= h[i]) cur++;
      while (cur < m) {
        long long w = p[cur] - x;
        w += min(h[i] - x, p[cur] - h[i]);
        if (w <= T)
          cur++;
        else
          break;
      }
    }
  }
  return cur >= m;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
  long long l = -1, r = (long long)(1e14);
  while (l + 1 < r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%I64d\n", r);
  return 0;
}
