#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1;
const int N = 1e6 + 1;
const long long mod = 1e9 + 7;
const int bits = 19;
bool check(vector<long long>& h, vector<long long>& p, long long val) {
  int st1 = 0, st2 = 0, n = h.size(), m = p.size();
  while (st1 < n && st2 < m) {
    if (h[st1] > p[st2]) {
      if (h[st1] - p[st2] <= val) {
        long long rem =
            max(val - 2LL * (h[st1] - p[st2]), (val - (h[st1] - p[st2])) / 2);
        while (st2 < m && h[st1] >= p[st2]) st2++;
        while (rem > 0 && st2 < m && p[st2] - h[st1] <= rem) st2++;
      }
    } else {
      while (st2 < m && p[st2] - h[st1] <= val) st2++;
    }
    st1++;
  }
  return st2 == m;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n), p(m);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  long long low = -1, high = inf;
  while (low + 1 < high) {
    long long mid = (high + low) / 2;
    if (check(h, p, mid)) {
      high = mid;
    } else {
      low = mid;
    }
  }
  cout << high << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  std::cout << std::fixed << std::setprecision(20);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
