#include <bits/stdc++.h>
using namespace std;
vector<long long> h, p;
int m, n;
string s;
int go(long long t) {
  int k = 0;
  long long T = t;
  for (int i = 0; i < n; i++) {
    if (k >= m) return 1;
    if (abs(h[i] - p[k]) > T) {
      if (h[i] > p[k]) return 0;
      continue;
    }
    t = T;
    t -= abs(h[i] - p[k]);
    vector<long long>::iterator low, up;
    if (h[i] > p[k]) {
      up = upper_bound(p.begin(), p.end(), p[k] + t);
      low = upper_bound(p.begin(), p.end(), h[i] + t / 2);
      k = max((up - p.begin()), low - p.begin());
    } else if (h[i] <= p[k]) {
      up = upper_bound(p.begin(), p.end(), p[k] + t);
      k = up - p.begin();
    }
  }
  if (k < m)
    return 0;
  else
    return 1;
}
int main() {
  cin >> n >> m;
  long long e;
  for (int i = 0; i < n; i++) {
    cin >> e;
    h.push_back(e);
  }
  for (int i = 0; i < m; i++) {
    cin >> e;
    p.push_back(e);
  }
  long long L = 0, R = max(h[n - 1], p[m - 1]) * 2;
  while (L < R) {
    long long o = (L + R) / 2;
    int x = go(o);
    if (x)
      R = o;
    else
      L = o + 1;
  }
  cout << L << endl;
}
