#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
const long double EPS = 1e-9;
const long double PI = fabsl(atan2l(0.0, -1.0));
int n, m;
long long h[111111];
long long p[111111];
void load() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%lld", &p[i]);
  }
}
inline bool can(long long x1, long long x2, long long x, long long t) {
  if (x <= x1) {
    return x2 - x <= t;
  }
  if (x >= x2) {
    return x - x1 <= t;
  }
  long long a = x - x1 + x2 - x1;
  long long b = x2 - x + x2 - x1;
  return min(a, b) <= t;
}
bool check(long long t) {
  int from = 0;
  for (int i = 0; i < n; i++) {
    if (from == m) {
      break;
    }
    int left = from;
    int right = m;
    while (right - left > 1) {
      int md = (left + right) / 2;
      if (can(p[from], p[md], h[i], t)) {
        left = md;
      } else {
        right = md;
      }
    }
    from = can(p[from], p[left], h[i], t) ? left + 1 : left;
  }
  return from == m;
}
void solve() {
  long long left = -1;
  long long right = 1LL << 60;
  while (right - left > 1) {
    long long md = (left + right) / 2;
    if (check(md)) {
      right = md;
    } else {
      left = md;
    }
  }
  cout << right << "\n";
}
int main() {
  clock_t start = clock();
  load();
  solve();
  ;
  return 0;
}
