#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65000000")
using namespace std;
long long h[100005];
long long p[100005];
long long n, m;
bool test(long long t) {
  int p1 = 0;
  for (int i = 0; p1 < m && i < n; ++i) {
    long long mnpos = h[i];
    long long rt = t;
    if (p[p1] <= h[i]) {
      mnpos = p[p1];
      rt -= h[i] - p[p1];
      if (rt >= 0)
        for (; p1 < m && p[p1] <= h[i]; ++p1)
          ;
      else
        return false;
    }
    for (; p1 < m && min(h[i] - mnpos, p[p1] - h[i]) + p[p1] - h[i] <= rt; ++p1)
      ;
  }
  return p1 == m;
}
int main() {
  scanf("%I64d", &(n));
  scanf("%I64d", &(m));
  for (int i = 0; i < n; ++i) scanf("%I64d", &(h[i]));
  for (int i = 0; i < m; ++i) scanf("%I64d", &(p[i]));
  long long from = 0;
  long long to = 3e15 + 5;
  while (from < to) {
    long long ser = from + to >> 1;
    if (test(ser))
      to = ser;
    else
      from = ser + 1;
  }
  cout << to << endl;
  return 0;
}
