#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100010];
long long p[100010];
long long ll_abs(long long n) {
  if (n < 0) return -n;
  return n;
}
bool gre(long long t) {
  long long unread = 0;
  for (int i = 0; i < n; i++) {
    long long d = ll_abs(p[unread] - h[i]);
    if (d <= t) {
      long long t_left = t - d;
      long long r_most = p[unread] + t_left;
      if (p[unread] < h[i]) {
        long long r_most2 = h[i] + (t - d) / 2;
        if (r_most2 > r_most) r_most = r_most2;
      }
      while (unread < m && p[unread] <= r_most) unread++;
      if (unread >= m) return true;
    }
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < m; i++) cin >> p[i];
  long long t_min = 0;
  long long t_max = ll_abs(h[0] - p[0]) + (p[m - 1] - p[0]);
  while (t_min < t_max) {
    long long mid = (t_min + t_max) / 2;
    if (gre(mid)) {
      t_max = mid;
    } else {
      t_min = mid + 1;
    }
  }
  cout << t_min << endl;
  return 0;
}
