#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long h[N], p[N];
int n, m;
vector<pair<long long, long long> > event;
bool can(long long touch) {
  int begin = 0;
  for (int i = 0; begin < m && i < n; i++) {
    if (p[begin] >= h[i]) {
      while (begin < m && p[begin] <= h[i] + touch) begin++;
    } else {
      long long len = h[i] - p[begin];
      if (len > touch) {
        return 0;
      } else {
        long long res = (touch - len * 2);
        if (res < len) {
          res = (touch - len) / 2;
        }
        while (begin < m && p[begin] <= h[i] + res) begin++;
      }
    }
  }
  return begin == m;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    event.push_back(make_pair(h[i], 0));
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
    event.push_back(make_pair(p[i], 1));
  }
  long long l = 0, r = (long long)1e12;
  while (l < r) {
    long long mid = l + r >> 1;
    if (can(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
