#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, m;
vector<long long> heads, pos;
bool check(long long mid) {
  vector<long long> tempHeads = heads, tempPos = pos;
  while (tempHeads.size() && tempPos.size()) {
    long long curr = tempHeads.back();
    long long currTarget = tempPos.back();
    if (currTarget >= curr) {
      currTarget = curr + mid;
      while (tempPos.size() && tempPos.back() <= currTarget) tempPos.pop_back();
    } else {
      double maxShift = max(mid - 2.0 * (curr - currTarget),
                            (mid - (curr - currTarget)) * 0.5);
      if (maxShift < 0) return false;
      while (tempPos.size() && tempPos.back() <= curr + maxShift)
        tempPos.pop_back();
    }
    tempHeads.pop_back();
  }
  return tempPos.empty();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%I64d", &x);
    heads.push_back(x);
  }
  reverse(heads.begin(), heads.end());
  for (int i = 0; i < m; i++) {
    long long x;
    scanf("%I64d", &x);
    pos.push_back(x);
  }
  reverse(pos.begin(), pos.end());
  long long left = 0, right = 3E10, ans = -1;
  while (left <= right) {
    long long mid = (left + right) / 2;
    if (check(mid)) {
      ans = mid, right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  printf("%I64d", ans);
  return 0;
}
