#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 50;
long long now[MAXN] = {0};
long long to[MAXN] = {0};
int n, m;
int zxttql(long long x) {
  long long idx = 1;
  for (int i = 1; i <= n; i++) {
    long long len = x;
    if (now[i] >= to[idx]) {
      if (x < now[i] - to[idx])
        return 0;
      else {
        len = max((len - now[i] + to[idx]) / 2, len - 2 * (now[i] - to[idx]));
        if (len < 0) len = 0;
      }
    }
    idx = upper_bound(to + 1, to + 1 + m, now[i] + len) - to;
    if (idx > m) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> now[i];
  for (int i = 1; i <= m; i++) cin >> to[i];
  long long L = 0, R = 1e18, mid, ans;
  while (L <= R) {
    mid = (L + R) / 2;
    if (zxttql(mid)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
